机器人不等待反应或消息。

问题描述 投票:0回答:1

所以你可以看到这是一个有两个选项的建议命令,但是当我输入.sug时,机器人发送了嵌入,这很好,但是他立即发送了A表情的信息,然后他立即发送了 "你的建议已经被填到了东西团队",我甚至没有做任何事情。也没有错误。我认为机器人不知为何把自己对自己消息的反应当成了用户的反应,然后他认为自己因为自己的反应而发送的 "Please suggest something for......"(可能)是用户的建议消息,所以他发送了 "Your suggestion has been filled to the stuff team"(你的建议已经被填到了stuff team)这里有一个截图的链接。https:/ibb.coKwMBmtc

execute(message, client, args) {
        const Discord = require('discord.js');

        let Embed = new Discord.MessageEmbed()
            .setColor('0x0099ff')
            .setDescription(`Suggestion categories`)
            .addField(`For what you want to suggest something?`, `\nA: I want to suggest something for the Website/Servers/Discord Server\nB: I want to suggest something for the CloudX Bot \n\nPlease react to this message with A or B`)

        message.channel.send(Embed)
        .then(function (message) {
            message.react("🇦")
            message.react("🇧")
            const filter = (reaction, user) => {
                return ['🇦', '🇧'].includes(reaction.emoji.name) && user.id;
        };

        message.awaitReactions(filter, { max: 1 })
                .then(collected => {
                    const reaction = collected.first();

                    if (reaction.emoji.name === '🇦') {
                        const filter = m => m.author.id === message.author.id;

                        message.channel.send(`Please provide a suggestion for the Website/Servers/Discord Server or cancel this command with "cancel"!`)

                        message.channel.awaitMessages(filter, { max: 1, })
                            .then(async (collected) => {
                                if (collected.first().content.toLowerCase() === 'cancel') {
                                    message.reply("Your suggestion has been cancelled.")
                                }
                                else {
                                    let embed1 = new Discord.MessageEmbed()
                                        .setColor('0x0099ff')
                                        .setAuthor(`${message.author.tag}`)
                                        .addField(`New Suggestion:`, `${collected.first().content}`)
                                        .setFooter(client.user.username, "attachment://CloudX.png")
                                        .setTimestamp();

                                    const channel = await client.channels.fetch("705781201469964308")
                                    channel.send({embed: embed1, files: [{
                                        attachment:'CloudX.png',
                                        name:'CloudX.png'
                                        }]})

                                    message.channel.send(`Your suggestion has been filled to the staff team. Thank you!`)
                                } 
                        })
                    }
                    if (reaction.emoji.name === '🇧') {
                        const filter = m => m.author.id === message.author.id;

                        message.channel.send(`Please provide a suggestion for the CloudX Bot or cancel this command with "cancel"!`)

                        message.channel.awaitMessages(filter, { max: 1, })
                            .then(async (collected) => {
                                if (collected.first().content.toLowerCase() === 'cancel') {
                                    message.reply("Your suggestion has been cancelled.")
                                }
                                else {
                                    let embed2 = new Discord.MessageEmbed()
                                        .setColor('0x0099ff')
                                        .setAuthor(`${message.author.tag}`)
                                        .addField(`New Suggestion:`, `${collected.first().content}`)
                                        .setFooter(client.user.username, "attachment://CloudX.png")
                                        .setTimestamp();

                                    const channel = await client.channels.fetch("702825446248808519")
                                    channel.send({embed: embed2, files: [{
                                        attachment:'CloudX.png',
                                        name:'CloudX.png'
                                        }]})

                                    message.channel.send(`Your suggestion has been filled to the staff team. Thank you!`)
                                } 
                        })
                    }    
                })
        })
    },
javascript async-await bots discord.js message
1个回答
1
投票

我想机器人为什么把他自己对自己信息的反应当作用户的反应呢?

你说的很对。机器人在收集自己的信息和反应,因为你没有使用 .then 发送后,所以 awaitMessagesawaitReactions 大致在你发送消息的同时被调用。

要解决这个问题,你需要使用 .then 为你的机器人采取的每一个动作(发送消息,做出反应)。

message.channel.send(Embed).then((message) => {
    message.react("🇦").then(() => {
        message.react("🇧").then(() => {
            message.awaitReactions(filter, { max: 1 }).then(collected => {
                // Do stuff with the collected reaction
            })
        })
    })
})

这样一来,它只会在上一个动作完成后运行下一段代码,避免收集自己的动作。

© www.soinside.com 2019 - 2024. All rights reserved.