Discord.js的角色反应

时间:2020-09-16 03:57:44

标签: javascript discord discord.js

我正在尝试编写具有反应角色的Discord机器人。我一直在获取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);
    }
})

2 个答案:

答案 0 :(得分:0)

您正在将_ = shell("-d", "uninstall", "\(self.gameID)") self.installationLabel.stringValue = "Previous version uninstalled! Installing APK..." _ = shell("-d", "install", "\(self.usernameFilePath)/Downloads/Bluebird Stuff/\(self.gameFolderName)/\(self.apkName)") self.installationLabel.stringValue = "APK installed! Setting permissions..." _ = shell("-d", "shell", "pm", "grant", "\(self.gameID)", "android.permission.RECORD_AUDIO") _ = shell("-d", "shell", "pm", "grant", "\(self.gameID)", "android.permission.READ_EXTERNAL_STORAGE") 分配给embedMsg嵌入。您无法对嵌入做出反应。尝试对使用https://discord.js.org#/docs/main/stable/class/Message?scrollTo=react

收到的消息做出反应

答案 1 :(得分:0)

您正在尝试直接对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