javascript - 自定义表情符号 react 角色

标签 javascript node.js discord.js

react 按钮工作正常,但唯一的问题是它在嵌入消息中显示自定义表情符号的 ID。
enter image description here
这是代码:

{name: 'reactionrole',
    description: "Sets up a reaction role message!",
    async execute(message, args, Discord, client) {
        const channel = '866637673937895457';
        const redTeamRole = message.guild.roles.cache.find(role => role.name === "Red");
        const yellowTeamRole = message.guild.roles.cache.find(role => role.name === "Yellow");
        const RandomTeamRole = message.guild.roles.cache.find(role => role.name === "olddrawinlmaooo");
 
        const redTeamEmoji = '🍉';
        const yellowTeamEmoji = '🍋';
        const RandomTeamEmoji = '889108655344091156';
        

 
        let embed = new Discord.MessageEmbed()
            .setColor('#e42643')
            .setTitle('Choose a team to play on!')
            .setDescription('Choosing a team will allow you to interact with your teammates!\n\n'
                + `${redTeamEmoji} for yellow team\n`
                + `${yellowTeamEmoji} for blue team\n`
                + `${RandomTeamEmoji} for random team`);
 
        let messageEmbed = await message.channel.send(embed);
        messageEmbed.react(redTeamEmoji);
        messageEmbed.react(yellowTeamEmoji);
        messageEmbed.react(RandomTeamEmoji);
 
        client.on('messageReactionAdd', async (reaction, user) => {
            if (reaction.message.partial) await reaction.message.fetch();
            if (reaction.partial) await reaction.fetch();
            if (user.bot) return;
            if (!reaction.message.guild) return;
 
            if (reaction.message.channel.id == channel) {
                if (reaction.emoji.name === redTeamEmoji) {
                    await reaction.message.guild.members.cache.get(user.id).roles.add(redTeamRole);
                }
                if (reaction.emoji.name === yellowTeamEmoji) {
                    await reaction.message.guild.members.cache.get(user.id).roles.add(yellowTeamRole);
                }
                if (reaction.emoji.name === RandomTeamEmoji) {
                    await reaction.message.guild.members.cache.get(user.id).roles.add(RandomTeamRole);
                }
            } else {
                return;
            }
 
        });
 
        client.on('messageReactionRemove', async (reaction, user) => {
 
            if (reaction.message.partial) await reaction.message.fetch();
            if (reaction.partial) await reaction.fetch();
            if (user.bot) return;
            if (!reaction.message.guild) return;
 
 
            if (reaction.message.channel.id == channel) {
                if (reaction.emoji.name === redTeamEmoji) {
                    await reaction.message.guild.members.cache.get(user.id).roles.remove(redTeamRole);
                }
                if (reaction.emoji.name === yellowTeamEmoji) {
                    await reaction.message.guild.members.cache.get(user.id).roles.remove(yellowTeamRole);
                }
                if (reaction.emoji.name === RandomTeamEmoji) {
                    await reaction.message.guild.members.cache.get(user.id).roles.remove(RandomTeamRole);
                }
            } else {
                return;
            }
 
        });

    }

}  }

最佳答案

用表情符号名称和 ID 替换 ID。它看起来像这样:<:yeah:735918408561852457>为了轻松获得它,只需在您想要的表情符号前面放一个\,然后将其发送到 channel 中,它就会为您提供那种格式。

关于javascript - 自定义表情符号 react 角色,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/69637436/

相关文章:

javascript - 我如何创建一个包含图像的多级下拉菜单,最好使用 css?

javascript - 为什么全局变量被认为是不好的做法? (node.js)

javascript - Discordjs - 获取后 lastMessageId 始终为空事件

javascript - 如何使不和谐机器人正确自动大写字符串的第一个字母?正则表达式

javascript - 如何将文字数组转换为 json

javascript - Angular 2 发送空帖子

node.js - 在 Node.js 中动态导入 webpack

javascript - 如何将 Discord.js 和 twit 相互集成,以在指定 channel 上进行实时 Twitter 提要

javascript - webpack/babel/react - 意外的 token 错误

javascript - UnhandledPromiseRejectionWarning : TypeError: res. 状态不是函数(NEXT JS)