简体   繁体   English

Discord.js 的角色反应

[英]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.我不断收到 embedMsg.react 不是一个函数,我也试过 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.您正在将embedMsg分配给嵌入的Server Roles 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尝试使用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.您正在尝试直接对msgEmbed本身做出反应,但您无法对嵌入做出反应。 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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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