简体   繁体   中英

Role Reactions for Discord.js

I'm trying to code a discord bot with reaction roles. I keep getting embedMsg.react is not a function, I've also tried embedMsg.message.react. I'm confused as to what's going on on.

client.on('message', message => {

    if(message.author.bot || message.embeds)

    embedMsg = message.embeds.find(msg => msg.title === 'Server Roles');
      if(embedMsg) 
      {

      embedMsg.react('755602275963109536')
            .then(() => message.react('755604749814071366'))
            .catch(() => console.error('One of the emojis failed to react.'));
            return;
      }
            

    if(message.content.toLowerCase() === '-roles')
    {
        const embed = new MessageEmbed();
        embed.setTitle("Server Roles");
        embed.setColor("GRAY");
        embed.setDescription(

        "<:V:755602275963109536>\n" +
        "<:USD:755604749814071366>\n" +
        "<:U:755605241067601960>\n" +
        "<:qt:755604978571280466>\n" +
        "<:QWE:755604795292909589>\n" +
        "<LOL:755605048666620075>\n\n" +
        "<:s:755604953229164594>\n" +
        "<:e:755604994656436346>\n" +
        "<:q:755605995195072603>\n\n" +
        "<:t:755605032124022814>"
        
        );
        

        message.channel.send(embed);
    }
})

You are assigning embedMsg to the Server Roles embed. You can't react to an embed. Try reacting to the message you received using https://discord.js.org#/docs/main/stable/class/Message?scrollTo=react

You are trying to react directly to msgEmbed itself, but you cannot react to an embed. Instead, you have to react to the message the embed is attached to.

// run the `find()` method, but this time use the ternary operator.
// if there is a find, use the message variable
// otherwise, return undefined
const msgEmbed = message.embeds.find(msg => msg.title === 'Server Roles') ? message : undefined

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM