简体   繁体   中英

My discord bot doesn't always trigger on reaction event

I got a problem with my ticket bot. I have a ticket bot that gives you 5 options, but the bot doesn't really work. Sometimes it does make a ticket on reaction sometimes it just adds the reaction but doesn't make a ticket. I have 2 bots with this issue now so I'm guess I'm just doing it wrong.

Also I'm getting no errors in my console, and I never have the issue my self but other people sometimes do!

bot.on('messageReactionAdd', (reaction, user) => {

    if (user.bot) {
        return;
    }

    reaction.users.remove(user.id)

    bot.users.fetch(user.id).then((user) => {

        let channelId = "";

        let query = `SELECT * FROM ticketMessage`;
        db.get(query, (err, row) => {

            let ticketMessage = row.MessageId;
            if (reaction.emoji.name == "🦖") {

                const startTicket = async (name) => {
                    reaction.message.channel.guild.channels.create(user.username + name, {
                            type: 'text'
                        })
                        .then(channel => {
                            let category = "";

category = reaction.message.channel.guild.channels.cache.find(c => c.id == settings["Categories"].ticketcategory && c.type == "category");

                            if (!category) {

                                user.send("Couldn't Process your ticket since there is no category setup for it!")

                            } else {

                                channel.setParent(category.id).then(() => {
                                    channelId = channel.id

                                    sendQuestions()
                                })

                            }

                        }).catch(console.error);
                }

                startTicket(" Dino Lines");


                const sendQuestions = async () => {

                    ticketChannel = bot.channels.cache.get(channelId)

                    await ticketChannel.updateOverwrite(user, {
                        VIEW_CHANNEL: true
                    });

                    const filter = m => m.author.id === user.id && m.channel === ticketChannel;

                    embed2 = new Discord.MessageEmbed();

                    embed2
                        .setDescription("What are the names of the dino's you would like to buy, Example => (T-rex, Bronto)?")
                        .setFooter(settings["Embeds"].displayname, settings["Embeds"].image)
                        .setColor(settings["Embeds"].color)
                        .setTimestamp()
                    ticketChannel.send(embed2);
                    ticketChannel.awaitMessages(filter, {
                            max: 1,
                            time: 120000
                        })
                        .then(collected => {

                            let dinoName = collected.first().content
                            embed3 = new Discord.MessageEmbed();

                            embed3
                                .setDescription("How many dino's would you like to buy, Example => (Dino1: 5, Dino2: 3)?")
                                .setFooter(settings["Embeds"].displayname, settings["Embeds"].image)
                                .setColor(settings["Embeds"].color)
                                .setTimestamp()
                            ticketChannel.send(embed3);
                            ticketChannel.awaitMessages(filter, {
                                    max: 1,
                                    time: 120000
                                })
                                .then(collected => {

                                    let amount = collected.first().content

                                    embed4 = new Discord.MessageEmbed();

                                    embed4
                                        .setDescription("What kind of currency would you like to use, Example => (Money, Items)?")
                                        .setFooter(settings["Embeds"].displayname, settings["Embeds"].image)
                                        .setColor(settings["Embeds"].color)
                                        .setTimestamp()
                                    ticketChannel.send(embed4);
                                    ticketChannel.awaitMessages(filter, {
                                            max: 1,
                                            time: 120000
                                        })
                                        .then(collected => {

                                            let currencyKind = collected.first().content
                                            embed5 = new Discord.MessageEmbed();

                                            embed5
                                                .setDescription("Do you want to submit this ticket? => (Yes, No)")
                                                .setFooter(settings["Embeds"].displayname, settings["Embeds"].image)
                                                .setColor(settings["Embeds"].color)
                                                .setTimestamp()
                                            ticketChannel.send(embed5);
                                            ticketChannel.awaitMessages(filter, {
                                                    max: 1,
                                                    time: 120000
                                                })
                                                .then(collected => {

                                                    let yn = collected.first().content

                                                    if (yn.toLowerCase() == "yes") {
                                                        embed1 = new Discord.MessageEmbed
                                                        ticketChannel.bulkDelete(8, true)
                                                        embed1
                                                            .setTitle(user.username + "'s Ticket")
                                                            .addFields({
                                                                name: "Buying Dino Lines",
                                                                value: "\u200b \n **Dino Names:** " + dinoName + "\n **Dino Count:** " + amount + "\n **Payment Methode:** " + currencyKind,
                                                                inline: true
                                                            }, )
                                                            .setFooter(settings["Embeds"].displayname, settings["Embeds"].image)
                                                            .setColor(settings["Embeds"].color)
                                                            .setTimestamp()
                                                        ticketChannel.send(embed1)
                                                    } else {
                                                        ticketChannel.send("Okay ticket canceled!");
                                                    }

                                                })


                                        })

                                })

                        })

                }

Discord only fires events to cached messages. You will either have to fetch the message on startup, or use the raw event instead, for example:

 bot.on('raw', (packet) => { if (packet.t == "MESSAGE_REACTION_ADD") { // Your code here } });

Keep in mind that you would have to re-work it if you used packets, as the data structure is different from what the messageReactionAdd event returns.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM