0
votes

So as you can see this is a suggestion command with 2 options but when i type .sug the bot sends the embed, thats good, but then he instlantly send the message for the A emoji and then he instantly sends "Your suggestion has been filled to the stuff team" without me even doing anything. There also is no error. I think the bot somewhy takes his own reaction to his own message as a reaction from the user and then he thinks the "Please suggest something for...." that he sent because of his own reaction (probably) is the suggestion message from the user and so he sends "Your suggestion has been filled to the stuff team" Here is a link to a screenshot: https://ibb.co/KwMBmtc

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!`)
                                } 
                        })
                    }    
                })
        })
    },
1

1 Answers

1
votes

I think the bot somewhy takes his own reaction to his own message as a reaction from the user

You are absolutely right. The bot is collecting its own messages and reactions, because you didn't use .then after sending them, so awaitMessages and awaitReactions are being called roughly at the same time you send the message.

To fix this, you need to use .then for each action (sending a message, reacting) your bot takes:

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

This way, it only runs the next bit of code after the last one has been completed, avoiding collection of its own actions.