【问题标题】:Slash commands only work on one Discord server? (discord.js v13)斜线命令仅适用于一台 Discord 服务器? (discord.js v13)
【发布时间】:2021-11-23 19:42:42
【问题描述】:

我注意到斜杠命令仅适用于一台 Discord 服务器:bot.guilds.cache.get(<GUILD_ID>).commands.set(command.name, command)
真的没有办法让命令在机器人已经存在的服务器上立即运行吗?我必须单独添加 ID 吗?我试过bot.guilds.cache.map(guild => guild.id).commands.set(command.name, command),但它给出了一个错误TypeError: Cannot read properties of undefined (reading 'set')

【问题讨论】:

    标签: discord.js


    【解决方案1】:

    使用Client#application 进行全局命令(适用于机器人所在的所有服务器,application.commands 范围)。

    公会专用命令使用Guild#commands

    bot.on("ready", () => {
      bot.application.commands.set([
        // Global command data
      ])
    })
    

    对于公会特定的命令:

    bot.guilds.cache.get("THE_GUILD_ID").commands.set(
      [
        // Guild command data
      ]
    )
    

    【讨论】:

    • 感谢您的帮助,现在斜线命令无处不在。
    • @user17481541 如果有帮助,请考虑在答案中添加复选标记
    • 我错了,没用。它适用于bot.guilds.cache.get().commans.set(),但不适用于bot.commands.set()。带有bot.guilds.cache.get().commands.set() 的斜杠命令会出现,但带有bot.commands.set() 的服务器中的斜杠命令不会出现。
    • 使用bot.application.commands.set
    • 显示了斜线命令,但是当我输入命令时,机器人认为并且不输出命令。
    猜你喜欢
    • 2022-01-07
    • 2021-11-03
    • 2021-10-19
    • 2022-01-03
    • 1970-01-01
    • 2021-06-11
    • 1970-01-01
    • 2021-10-06
    • 1970-01-01
    相关资源
    最近更新 更多