iam*_*k3v 0 javascript node.js discord discord.js
突然之间,我在大多数交互中不断收到此错误,并且我的机器人只是发送“机器人正在思考......”。
\n[UnhandledRejection] DiscordAPIError: Unknown interaction\n at RequestHandler.execute (/Users/main/Desktop/Discordbots/gamerscavern/node_modules/discord.js/src/rest/RequestHandler.js:349:13)\n at processTicksAndRejections (node:internal/process/task_queues:96:5)\n at async RequestHandler.push (/Users/main/Desktop/Discordbots/gamerscavern/node_modules/discord.js/src/rest/RequestHandler.js:50:14)\n at async SelectMenuInteraction.reply (/Users/main/Desktop/Discordbots/gamerscavern/node_modules/discord.js/src/structures/interfaces/InteractionResponses.js:98:5)\nRun Code Online (Sandbox Code Playgroud)\n示例此帮助命令。interaction.update()当另一个用户与收集器和过滤器中的部件交互时,它会返回未知的交互。我不知道为什么会发生这种情况。正如所提到的,就在几个小时前,它还运行良好。
这是我的代码:
\n帮助命令:
\nconst {\n Client,\n Message,\n MessageEmbed,\n MessageActionRow,\n MessageSelectMenu,\n} = require(\'discord.js\');\n\nmodule.exports = {\n name: \'help\',\n description: \'List all of my commands or info about a specific command.\',\n aliases: [\'commands\'],\n usage: \'[command name]\',\n category: \'info\',\n cooldown: 3,\n /**\n *\n * @param {Client} client\n * @param {Message} message\n * @param {String[]} args\n */\n execute: async (client, message, args, prefix) => {\n if (message.author.bot) return;\n const data = [];\n const { commands } = message.client;\n\n const emojis = {\n config: \'\xe2\x9a\x99\xef\xb8\x8f\',\n info: \'\xe2\x84\xb9\xef\xb8\x8f\',\n moderation: \'\',\n owner: \'\',\n utility: \'\',\n voice: \'\',\n welcoming: \'\',\n };\n\n if (!args[0]) {\n const directories = [\n ...new Set(client.commands.map((cmd) => cmd.category)),\n ].filter((e) => e !== \'secrets\' && e !== undefined);\n\n const formatString = (str) =>\n `${str[0].toUpperCase()}${str.slice(1).toLowerCase()}`;\n\n const categories = directories.map((dir) => {\n const getCommands = client.commands\n .filter((cmd) => cmd.category === dir)\n .map((cmd) => {\n return {\n name: cmd.name || \'There is no name\',\n description:\n cmd.description ||\n \'There is no description for this command\',\n };\n });\n\n return {\n directory: formatString(dir),\n commands: getCommands,\n };\n });\n\n const initialEmbed = new MessageEmbed()\n .setTitle(\'Developer: Kev#1880\')\n .setDescription(\n \'~~\xe2\x80\x94\xe2\x80\x94\xe2\x80\x94\xe2\x80\x94\xe2\x80\x94\xe2\x80\x94\xe2\x80\x94\xe2\x80\x94\xe2\x80\x94\xe2\x80\x94\xe2\x80\x94\xe2\x80\x94\xe2\x80\x94\xe2\x80\x94\xe2\x80\x94~~\\n** Links \xe2\x9e\xbc ** [Invite](https://discord.com/api/oauth2/authorize?client_id=711371556504207423&permissions=8&scope=bot) |\xc2\xa0[Server](https://discord.gg/XkCTA88) | [Upvote](https://top.gg/bot/711371556504207423/vote) \\n~~\xe2\x80\x94\xe2\x80\x94\xe2\x80\x94\xe2\x80\x94\xe2\x80\x94\xe2\x80\x94\xe2\x80\x94\xe2\x80\x94\xe2\x80\x94\xe2\x80\x94\xe2\x80\x94\xe2\x80\x94\xe2\x80\x94\xe2\x80\x94\xe2\x80\x94~~\\n\\n**Please choose a category in the dropdown menu**\'\n )\n .setColor(\'#5787E8\')\n .setThumbnail(client.user.displayAvatarURL({ format: \'png\' }))\n .setFooter(\n `Requested by: ${message.author.tag}`,\n message.author.displayAvatarURL({ format: \'png\' })\n )\n .setTimestamp();\n\n const components = (state) => [\n new MessageActionRow().addComponents(\n new MessageSelectMenu()\n .setCustomId(\'help-menu\')\n .setPlaceholder(\'Please select a category\')\n .setDisabled(state)\n .addOptions(\n categories.map((cmd) => {\n return {\n label: cmd.directory,\n value: cmd.directory.toLowerCase(),\n description: `Commands from ${cmd.directory} category`,\n emoji:\n emojis[cmd.directory.toLowerCase()] ||\n null,\n };\n })\n )\n ),\n ];\n\n const initialMessage = await message.channel.send({\n embeds: [initialEmbed],\n components: components(false),\n });\n\n const filter = async (interaction) => {\n if (interaction.user.id === message.author.id) {\n return true;\n }\n interaction.reply({\n content: `This is not your help menu, create your own with >help!`,\n ephemeral: true,\n });\n return false;\n };\n\n const collector = initialMessage.createMessageComponentCollector({\n filter,\n componentType: \'SELECT_MENU\',\n time: 600000,\n });\n\n collector.on(\'collect\', (interaction) => {\n console.log(interaction);\n const [directory] = interaction.values;\n const category = categories.find(\n (x) => x.directory.toLowerCase() === directory\n );\n\n const categoryEmbed = new MessageEmbed()\n .setTitle(`${formatString(directory)} commands`)\n .setDescription(\n \'~~\xe2\x80\x94\xe2\x80\x94\xe2\x80\x94\xe2\x80\x94\xe2\x80\x94\xe2\x80\x94\xe2\x80\x94\xe2\x80\x94\xe2\x80\x94\xe2\x80\x94\xe2\x80\x94\xe2\x80\x94\xe2\x80\x94\xe2\x80\x94\xe2\x80\x94~~\\n** Links \xe2\x9e\xbc ** [Invite](https://discord.com/api/oauth2/authorize?client_id=711371556504207423&permissions=8&scope=bot) |\xc2\xa0[Server](https://discord.gg/XkCTA88) | [Upvote](https://top.gg/bot/711371556504207423/vote) \\n~~\xe2\x80\x94\xe2\x80\x94\xe2\x80\x94\xe2\x80\x94\xe2\x80\x94\xe2\x80\x94\xe2\x80\x94\xe2\x80\x94\xe2\x80\x94\xe2\x80\x94\xe2\x80\x94\xe2\x80\x94\xe2\x80\x94\xe2\x80\x94\xe2\x80\x94~~\\n\\n**Here are the list of commands**\'\n )\n .setColor(\'#5787E8\')\n .addFields(\n category.commands.map((cmd) => {\n return {\n name: `\\`${cmd.name}\\``,\n value: cmd.description,\n inline: true,\n };\n })\n )\n .setThumbnail(\n client.user.displayAvatarURL({ format: \'png\' })\n )\n .setFooter(\n `Requested by: ${message.author.tag}`,\n message.author.displayAvatarURL({ format: \'png\' })\n )\n .setTimestamp();\n\n interaction.update({\n embeds: [categoryEmbed],\n });\n });\n\n collector.on(\'end\', () => {\n const ranOut = new MessageEmbed()\n .setColor(\'RED\')\n .setTitle(\'Oops!\')\n .setDescription(\n \'Interaction ran out of time! Please create a new help menu!\'\n )\n .setThumbnail(\n client.user.displayAvatarURL({ format: \'png\' })\n )\n .setFooter(\n `Requested by: ${message.author.tag}`,\n message.author.displayAvatarURL({ format: \'png\' })\n )\n .setTimestamp();\n\n initialMessage.edit({\n embeds: [ranOut],\n components: components(true),\n });\n });\n }\n if (args[0]) {\n const name = args[0].toLowerCase();\n const command =\n commands.get(name) ||\n commands.find((c) => c.aliases && c.aliases.includes(name));\n if (!command) {\n return message.reply({\n content: "that\'s not a valid command!",\n });\n }\n\n // data.push(`**Name:** ${command.name}`);\n\n if (command.aliases)\n data.push(`**Aliases:** ${command.aliases.join(\', \')}`);\n if (command.description)\n data.push(`**Description:** ${command.description}`);\n if (command.nb) data.push(`**NB:** ${command.nb}`);\n if (command.userPermissions)\n data.push(\n `**User Permissions:** \\`${command.userPermissions.join(\n \', \'\n )}\\``\n );\n if (command.botPermissions)\n data.push(\n `**Bot Permissions:** ${command.botPermissions\n .map((perm) => {\n return `\\`${perm}\\``;\n })\n .join(\', \')}`\n );\n if (command.usage)\n data.push(\n `**Usage:** \\`${prefix}${command.name} ${command.usage}\\``\n );\n if (command.examples)\n data.push(`**Examples:**\n ${command.examples\n .map((example) => {\n return `\\`${prefix}${command.name} ${example}\\``;\n })\n .join(\'\\n\')}\n `);\n\n data.push(`**Cooldown:** ${command.cooldown || 3} second(s)`);\n\n const commandHelp = new MessageEmbed()\n .setTitle(`Command: **${command.name}**`)\n .setColor(\'#5787E8\')\n .setDescription(`${data.join(\'\\n\')}`)\n .setFooter(\n `Requested by: ${message.author.tag}`,\n message.author.displayAvatarURL({ format: \'png\' })\n );\n\n return message.reply({ embeds: [commandHelp] });\n }\n },\n};\nRun Code Online (Sandbox Code Playgroud)\n交互创建事件:
\nconst blacklist = require(\'../../models/blacklists.js\');\nconst guildBlacklist = require(\'../../models/guildBlacklist.js\');\nconst reactionRoles = require(\'../../models/reactionRoles.js\');\nmodule.exports = async (Discord, client, interaction) => {\n //Slash Command Handling\n if (interaction.isCommand()) {\n // await interaction.deferReply();\n //blacklists\n const bl = await blacklist.findOne({ Client: client.user.id });\n if (bl) {\n if (bl.Users) {\n if (bl.Users.includes(interaction.user.id)) return;\n }\n }\n\n const gbl = await guildBlacklist.findOne({\n Guild: interaction.guild.id,\n });\n if (gbl) {\n if (gbl.Users) {\n if (gbl.Users.includes(interaction.user.id)) return; \n }\n }\n\n const cmd = client.slashCommands.get(interaction.commandName);\n if (!cmd) return interaction.reply({ content: \'An error has occured\' });\n\n const args = [];\n\n for (let option of interaction.options.data) {\n if (option.type === \'SUB_COMMAND\') {\n if (option.name) args.push(option.name);\n option.options?.forEach((x) => {\n if (x.value) args.push(x.value);\n });\n } else if (option.value) args.push(option.value);\n }\n interaction.member = interaction.guild.members.cache.get(\n interaction.user.id\n );\n\n if (!interaction.member.permissions.has(cmd.userPermissions || []))\n return interaction.reply({\n content: \'You do not have the permissions to use this command!\',\n ephemeral: true,\n });\n\n cmd.execute(client, interaction, args);\n }\n\n //Context Menu Handling\n if (interaction.isContextMenu()) {\n await interaction.deferReply();\n const command = client.slashCommands.get(interaction.commandName);\n if (command) command.execute(client, interaction);\n }\n\n //Reaction Roles Handling\n if (interaction.isSelectMenu()) {\n await interaction.deferReply();\n const reactionPanel = await reactionRoles.findOne({\n guildId: interaction.guildId,\n \'reactionPanels.customId\': `${interaction.customId}`,\n });\n\n if (reactionPanel) {\n //if (interaction.customId !== \'reaction-roles\') return;\n const roleId = interaction.values[0];\n\n const role = interaction.guild.roles.cache.get(roleId);\n if (!role) return;\n\n const memberRoles = interaction.member.roles;\n\n const hasRole = memberRoles.cache.has(roleId);\n\n if (hasRole) {\n memberRoles.remove(roleId);\n interaction.followUp({\n content: `${role.name} has been removed from you`,\n ephemeral: true,\n });\n } else {\n memberRoles.add(roleId);\n interaction.followUp({\n content: `${role.name} has been added to you`,\n ephemeral: true,\n });\n }\n }\n }\n};\nRun Code Online (Sandbox Code Playgroud)\n
如果您在 3 秒内没有回复或确认交互。有冷却时间!
用户将看到交互失败并且回复门已关闭。
但是,如果您推迟回复并稍后进行编辑,则大门将打开,直到您更新推迟或编辑回复。以下是如何执行此操作,以下是有关它的文档。
interaction.deferReply();
// Do some stuff that takes time right here...
interaction.editReply({ content: "replied" });
Run Code Online (Sandbox Code Playgroud)
要回答有关机器人发送的其他问题Bot is thinking...,
当您推迟而不编辑回复后,就会发生这种情况。
它会一直这样,直到你做某事。