【问题标题】:Little problem with slash commands (discord.js v13)斜杠命令的小问题(discord.js v13)
【发布时间】:2022-01-03 07:09:27
【问题描述】:

斜杠命令运行良好,没有麻烦,用简单的代码设置:bot.commands.set(command.name, command)
但我注意到它们仅在机器人运行并将其添加到 Discord 服务器时才设置。如果机器人已经在 Discord 服务器上,并且稍后出现了新命令,则命令不会出现在列表中。我通过第二次邀请解决了这个问题,但是列表中的命令开始加倍,就好像它们在克隆自己一样。这可以解决吗?

【问题讨论】:

  • AFAIK 您实际上无法删除斜杠命令,但它们可能会在一段时间后消失。如果确实存在问题,您可以通过 Developer Portal 删除并重新创建应用程序。
  • @Shay 您绝对可以删除斜杠命令,您的回答极具误导性。您可以使用bot.application.commands.delete(全局命令)删除斜杠命令,其中 bot 是 DiscordClient 或公会命令:guild.commands.delete,其中 guild 是目标公会。这些都是函数,并且需要一个命令 id。您可以使用以下方式获取命令 ID:bot.commands.fetch().then(c=> console.log(c))(global cmds)、guild.commands.fetch().then(c=>console.log(c))(server commands)。
  • @Jeffplays2005 可以作为答案发布,因为它回答了问题 - 但可能需要更详细地说明

标签: discord.js


【解决方案1】:

您可以从全局命令或服务器命令中删除斜杠命令。获取命令然后记录或使用其他方法向您显示命令 id 将允许您使用删除方法。

您可以使用bot.application.commands.delete('id here') 删除斜杠命令。 (全局命令)其中 bot 是 DiscordClient 或 guild 命令:guild.commands.delete('id here'),其中 guild 是目标 Guild。

这些都是函数,并且需要一个命令 ID。您可以使用以下方式获取命令 ID:bot.application.commands.fetch().then(c=> console.log(c))(global cmds)、guild.commands.fetch().then(c=>console.log(c))(server commands)

【讨论】:

  • TypeError: bot.commands.fetch is not a function
  • 天哪,我忘了,它的 bot.application.commands.fetch,抱歉误导性的答案,我现在就编辑它!
  • 哦,好的,谢谢。
  • 是的,它正在工作,非常感谢。
猜你喜欢
  • 2022-01-07
  • 1970-01-01
  • 2022-01-09
  • 2021-11-09
  • 2021-12-15
  • 2022-07-05
  • 2021-10-19
  • 2022-11-19
  • 2021-11-11
相关资源
最近更新 更多