简体   繁体   English

在 discord.js 中重新启动后,如何使反应仍然有效?

[英]How do I make reaction still work after a restart in discord.js?

I'm trying to make a ticket bot, which lets you react to a message, and then it will create a channel but every time I restart the bot, the reactions don't work anymore.我正在尝试制作一个票务机器人,它可以让您对消息做出反应,然后它会创建一个频道,但是每次我重新启动机器人时,反应都不再起作用。 How do I make that work?我该如何做?

let messageEmbed = await message.channel.send(ticketEmbed);
messageEmbed.react("1️⃣");
messageEmbed.react("2️⃣");
messageEmbed.react("3️⃣");
messageEmbed.react("4️⃣");

client.on("messageReactionAdd", async (reaction, user) => {
    if (reaction.message.partial) await reaction.message.fetch();
    if (reaction.partial) await reaction.fetch();
    if (user.bot) return;
    if (!reaction.message.guild) return;

    if (reaction.emoji.name === firstreaction) {
        const categoryId = "822577084223586364";
        var username = reaction.message.guild.members.cache.get(user.id);
        var userDiscriminator = reaction.message.guild.members.cache.get(user.id).discriminator;
        var ticketExists = false;

        message.guild.channels.cache.forEach((channel) => {
            if (channel.name == `${reaction.user}` + "Playerreport") {
                var ticketExists = true;
                message.username.send("You already have an open ticket!");

                return;
            }
        });
        if (ticketExists) return;

        message.guild.channels
            .create(`${reaction.user}` + "Playerreport", {
                type: "text",
            })
            .then((createdchannel) => {
                createdchannel.setParent(categoryId).then((settedParent) => {
                    settedParent.updateOverwrite(
                        message.guild.roles.cache.find((x) => x.name === "@everyone"),
                        {
                            SEND_MESSAGES: false,
                            VIEW_CHANNEL: false,
                        }
                    );
                    settedParent.updateOverwrite(username, {
                        SEND_MESSAGES: true,
                        VIEW_CHANNEL: true,
                        READ_CHANNEL: true,
                        CREATE_INSTANT_INVITE: false,
                        ATTACH_FILES: true,
                        CONNECT: true,
                        ADD_REACTIONS: true,
                    });
                    var embedParent = new Discord.MessageEmbed()
                        .setTitle(`Hey ${username}, who do you want to report, and why?`)
                        .setDescription("Staff will try to help you as soon as possible")
                        .setThumbnail("https://cdn.discordapp.com/attachments/790156012119392287/821827094916759603/image_2.png");

                    settedParent.send(embedParent);
                });
            });
    }
});

You should try to move the messageReactionAdd event outside of your command file, as your code will most likely break, unless you re type the command.您应该尝试将messageReactionAdd事件移到命令文件之外,因为您的代码很可能会中断,除非您重新键入命令。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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