首页 > 解决方案 > Discord.js 'awaitReactions 不是函数' 错误

问题描述

当用户单击机器人嵌入的表情符号时,我试图让机器人做出反应。

我在控制台中收到:

UnhandledPromiseRejectionWarning:TypeError:chestEmbed.awaitReactions 不是函数

编码:

module.exports = {
    name: 'enterhouse',
    aliases: 'eh',
    permissions: ["ADMINISTRATOR", "MANAGE_MESSAGES", "CONNECT"],
    description: "Pick a number",
    async execute(client, message, args, Discord){

        const chestEmbed = new MessageEmbed()
        .setColor('#FFA500')
        .setImage('https://imageURL.jpg');

        message.channel.send(chestEmbed).then(chestEmbed => {chestEmbed.react('1️⃣').then(() => chestEmbed.react('2️⃣').then(() => chestEmbed.react('3️⃣')))}
          )
        .catch(() => console.error('One of the emojis failed to react.'));

        const filter = (reaction, user) => {
            return (['1️⃣', '2️⃣', '3️⃣'].includes(reaction.emoji.name) && user.id === message.author.id);
        };

        chestEmbed.awaitReactions(filter, { max: 1, time: 60000, errors: ['time'] })
            .then(collected => {
                const reaction = collected.first();

                if (reaction.emoji.name === '1️⃣') {
                    chestEmbed.delete();
                    message.reply('you reacted with 1');
                } else if (reaction.emoji.name === '2️⃣') {
                    message.reply('you reacted with 2');
                } else {
                    message.reply('you reacted with 3');
                }
            })
            .catch(collected => {
                message.reply('Time is up, you did not react.');
            });
    }
}

当它是 message.awaitReactions 时它工作得很好。

非常感谢任何帮助!

标签: javascriptnode.jsdiscorddiscord.jsbots

解决方案


您正在等待来自嵌入的消息,它本身不是嵌入的消息。
简单修复:

...
chestEmbed = await message.channel.send(chestEmbed)
...

完整代码:

module.exports = {
    name: 'enterhouse',
    aliases: 'eh',
    permissions: ["ADMINISTRATOR", "MANAGE_MESSAGES", "CONNECT"],
    description: "Pick a number",
    async execute(client, message, args, Discord) {
        const chestEmbed = new MessageEmbed()
        .setColor('#FFA500')
        .setImage('https://imageURL.jpg');

        chestEmbed = await message.channel.send(chestEmbed)
        chestEmbed.react('1️⃣').then(() => chestEmbed.react('2️⃣')).then(() => chestEmbed.react('3️⃣'))

        const filter = (reaction, user) => {
            return (['1️⃣', '2️⃣', '3️⃣'].includes(reaction.emoji.name) && user.id === message.author.id);
        };

        chestEmbed.awaitReactions(filter, { max: 1, time: 60000, errors: ['time'] })
          .then(collected => {
              const reaction = collected.first();

               if (reaction.emoji.name === '1️⃣') {
                   chestEmbed.delete();
                   message.reply('you reacted with 1');
               } else if (reaction.emoji.name === '2️⃣') {
                   message.reply('you reacted with 2');
               } else {
                   message.reply('you reacted with 3');
               }
          })
          .catch(collected => {
              message.reply('Time is up, you did not react.');
          });
    }
}

推荐阅读