Meg*_*aft 2 javascript node.js discord discord.js
我正在创建一个斜杠命令,以便在用户使用 /help 时发送有关命令的信息,但是当我添加多个命令时,我只会收到此错误:
\nE:\\v13\\node_modules\\discord.js\\src\\rest\\RequestHandler.js:298\n throw new DiscordAPIError(data, res.status, request);\n ^\n\nDiscordAPIError: Unknown interaction\n at RequestHandler.execute (E:\\v13\\node_modules\\discord.js\\src\\rest\\RequestHandler.js:298:13)\n at processTicksAndRejections (node:internal/process/task_queues:96:5)\n at async RequestHandler.push (E:\\v13\\node_modules\\discord.js\\src\\rest\\RequestHandler.js:50:14)\n at async CommandInteraction.reply (E:\\v13\\node_modules\\discord.js\\src\\structures\\interfaces\\InteractionResponses.js:98:5) {\n method: \'post\',\n path: \'/interactions/[EDITED]/callback\',\n code: 10062,\n httpStatus: 404,\n requestData: {\n json: {\n type: 4,\n data: {\n content: undefined,\n tts: false,\n nonce: undefined,\n embeds: [\n {\n title: \'Help Menu \xe2\x9e\x9e test\',\n type: \'rich\',\n description: null,\n url: null,\n timestamp: 0,\n color: 3447003,\n fields: [Array],\n thumbnail: null,\n image: null,\n author: null,\n footer: [Object]\n }\n ],\n components: undefined,\n username: undefined,\n avatar_url: undefined,\n allowed_mentions: undefined,\n flags: undefined,\n message_reference: undefined,\n attachments: undefined,\n sticker_ids: undefined\n }\n },\n files: []\n }\n}\nRun Code Online (Sandbox Code Playgroud)\n我的代码:
\nE:\\v13\\node_modules\\discord.js\\src\\rest\\RequestHandler.js:298\n throw new DiscordAPIError(data, res.status, request);\n ^\n\nDiscordAPIError: Unknown interaction\n at RequestHandler.execute (E:\\v13\\node_modules\\discord.js\\src\\rest\\RequestHandler.js:298:13)\n at processTicksAndRejections (node:internal/process/task_queues:96:5)\n at async RequestHandler.push (E:\\v13\\node_modules\\discord.js\\src\\rest\\RequestHandler.js:50:14)\n at async CommandInteraction.reply (E:\\v13\\node_modules\\discord.js\\src\\structures\\interfaces\\InteractionResponses.js:98:5) {\n method: \'post\',\n path: \'/interactions/[EDITED]/callback\',\n code: 10062,\n httpStatus: 404,\n requestData: {\n json: {\n type: 4,\n data: {\n content: undefined,\n tts: false,\n nonce: undefined,\n embeds: [\n {\n title: \'Help Menu \xe2\x9e\x9e test\',\n type: \'rich\',\n description: null,\n url: null,\n timestamp: 0,\n color: 3447003,\n fields: [Array],\n thumbnail: null,\n image: null,\n author: null,\n footer: [Object]\n }\n ],\n components: undefined,\n username: undefined,\n avatar_url: undefined,\n allowed_mentions: undefined,\n flags: undefined,\n message_reference: undefined,\n attachments: undefined,\n sticker_ids: undefined\n }\n },\n files: []\n }\n}\nRun Code Online (Sandbox Code Playgroud)\n当我只有一个命令时它工作得很好commands,但如果我添加第二个命令,我可以使用该命令一次,如果我再次使用它 - 我的机器人崩溃了!它还找不到第二个命令,只能看到第一个命令
更新1:我稍微更改了代码,现在它可以找到第二个命令,但如果我尝试通过别名搜索命令,它会向我发送命令信息并使机器人崩溃,并出现相同的错误!\n基本上我只是添加了:
\n interaction.client.commands.each((cmd) => {\n if(cmd.name == args[0].toLowerCase() || cmd.aliases.includes(args[0].toLowerCase())) { \n embed.setTitle("Help Menu" + " " + "\xe2\x9e\x9e" + " " + `${cmd.name}`)\n embed.addField("**Description**", `${cmd.description}`, false)\n embed.addField("**Usage**", `${cmd.usage}`, true)\n embed.addField("**Aliases**", `${cmd.alias}`, true)\n embed.addField("**Examples**", `${cmd.examples}`, true)\n interaction.reply({ embeds: [embed], ephemeral: false });\n } else {\n interaction.reply({ content: `Command you requested help for does not exist!`, ephemeral: true });\n }\n })\nRun Code Online (Sandbox Code Playgroud)\n
小智 7
您的应用程序需要在 3 秒内响应 Discord 交互,否则交互会从 Discord 结束,您将收到此错误。
对于斜杠命令,您可以通过执行以下命令来延迟响应:
await interaction.deferReply({ ephemeral: true });
Run Code Online (Sandbox Code Playgroud)
然后,这将等待您运行所需的任何逻辑并跟进:
interaction.editReply({ embeds: [embed] })
Run Code Online (Sandbox Code Playgroud)
请注意,您只能在初始响应上设置临时标志,因此您需要知道在推迟时它是否会是临时的。
另请注意,如果您为斜杠命令实现自动完成,则无法推迟。您需要在 3 秒时间内发送完整回复。
我建议阅读discordjs 指南网站,特别是此页面。
| 归档时间: |
|
| 查看次数: |
17128 次 |
| 最近记录: |