1
votes

I am having issues trying to get my discord bot to add a role based on an emoji reaction. When I use the command my bot will embed the message and emoji, but the emoji is not clickable. Also, when I type the command I get the error (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

1 Answers

0
votes

Your Pug_Emoji variable needs to be either a unicode character or the ID of the emoji, so for example const Pug_Emoji = '12317236871638731'; or const Pug_Emoji = '🐕'. A useful site for unicode emoji is here: https://emojipedia.org. This answer gives a little more information about getting the ID of the emoji.