在表情符号反应后让不和谐机器人分配角色时遇到问题

时间:2021-02-21 23:01:58

标签: javascript discord discord.js bots

我在尝试让我的不和谐机器人根据表情符号反应添加角色时遇到问题。当我使用命令时,我的机器人将嵌入消息和表情符号,但表情符号不可点击。此外,当我输入命令时,我收到错误 (node:12916) UnhandledPromiseRejectionWarning: DiscordAPIError: Unknown Emoji

module.exports = {
name: 'reactionrole',
description: "Sets up a reaction role message!",
async execute(message, args, Discord, client) {
    const channel = '810124665870325648';
    const Pug_Role = message.guild.roles.cache.find(role => role.name === "Pugs");
    

    const Pug_Emoji = ':gun:';
    

    let embed = new Discord.MessageEmbed()
        .setColor('#e42643')
        .setTitle('Pugs Click Here!')
        .setDescription('Choosing Pug will allow you to join some channels!\n\n'
            + `${Pug_Emoji} Pugs`
            );

    let messageEmbed = await message.channel.send(embed);
    messageEmbed.react(Pug_Emoji);
    

    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 === Pug_Emoji) {
                await reaction.message.guild.members.cache.get(user.id).roles.add(Pug_Role);
            }
            
        } 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 === Pug_Emoji) {
                await reaction.message.guild.members.cache.get(user.id).roles.remove(Pug_Role);
            }
            
        } else {
            return;
        }
    });
}

}

1 个答案:

答案 0 :(得分:0)

您的 Pug_Emoji 变量需要是 Unicode 字符或表情符号的 ID,例如 const Pug_Emoji = '12317236871638731';const Pug_Emoji = '?'。一个有用的 unicode 表情符号网站在这里:https://emojipedia.orgThis answer 提供了有关获取表情符号 ID 的更多信息。