当有人用表情符号 (discord.js) 做出反应时,如何编辑消息?

时间:2020-12-26 14:38:59

标签: javascript node.js discord discord.js bots

我想创建一个帮助屏幕,您可以使用反应滚动浏览。


例如

  1. 如果您对信息表情符号做出反应,机器人的消息将被编辑以显示信息页面。
  2. 现在,我可以在有人发送以“;help”开头的消息时发送帮助消息,并且我可以让机器人对消息做出反应。

但是,我无法让我的机器人删除用户的反应,也无法让它编辑我的消息。

这是代码。提前感谢您的帮助!

client.on('message', message => {
    if (message.author !== null && message.author.bot) return;
    if (message.toString().startsWith(';help')) {
        const helpPi = new Discord.MessageEmbed()
        .setTitle('Help and commands')
        .setColor('0004ff')
        .setDescription('This is the help menu for available commands. Here is the table of contents:\n> 1 - Commands\n> 2 - More info.')
        const helpP1 = new Discord.MessageEmbed()
        .setTitle('Help and commands')
        .setColor('0004ff')
        .setDescription('Command A\nCommand B')
        const helpP2 = new Discord.MessageEmbed()
        .setTitle('Help and commands')
        .setColor('0004ff')
        .setDescription('More info.')
        message.channel.send(helpPi).then(sentMessage => {
            sentMessage.react('ℹ️')
            sentMessage.react('1️⃣')
            sentMessage.react('2️⃣')
            client.on('messageReactionAdd', reaction => {
                if (reaction == '1️⃣') {
                    sentMessage.edit(helpP1)
                }
                else if (reaction == '2️⃣') {
                    sentMessage.edit(helpP2)
                }
                else if (reaction == 'ℹ️') {
                    sentMessage.edit(helpPi)
                }
            })
        })
    }
});

0 个答案:

没有答案