【问题标题】:Role Reactions for Discord.jsDiscord.js 的角色反应
【发布时间】:2020-09-16 18:16:08
【问题描述】:

我正在尝试编写一个具有反应角色的不和谐机器人。我不断收到 embedMsg.react 不是函数,我也尝试过 embedMsg.message.react。我对发生了什么感到困惑。

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);
    }
})

【问题讨论】:

    标签: javascript discord discord.js


    【解决方案1】:

    您正试图直接对msgEmbed 本身做出反应,但您无法对嵌入做出反应。相反,您必须对嵌入的附加消息做出反应。

    // 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
    

    【讨论】:

      【解决方案2】:

      您正在将 embedMsg 分配给 Server Roles 嵌入。您无法对嵌入做出反应。尝试使用 https://discord.js.org#/docs/main/stable/class/Message?scrollTo=react 对收到的消息做出反应

      【讨论】:

        猜你喜欢
        • 2021-02-07
        • 1970-01-01
        • 2021-12-14
        • 2021-09-11
        • 1970-01-01
        • 2021-01-07
        • 2020-08-30
        • 2020-07-06
        相关资源
        最近更新 更多