【问题标题】:Use Slash Commands in all servers where have a bot without GuildID (Discord.js v12)在所有有没有 GuildID (Discord.js v12) 的机器人的服务器中使用斜杠命令
【发布时间】:2021-09-26 13:34:12
【问题描述】:

我希望人们能够在任何服务器上对我的机器人使用 Slash 命令,只要机器人在那里。我已进一步授予机器人application.commands 权限。我引用了this answer,但它似乎需要服务器的 GuildID。我可以允许任何使用 Slash 命令的人在没有 GuildID 的情况下使用我的机器人吗?人们如何使用它? (我使用命令处理程序)

对不起我的英语不好

【问题讨论】:

    标签: javascript node.js discord discord.js


    【解决方案1】:

    您可能想使用global slash command。全局意味着它适用于机器人所在的所有公会,您无需提供任何公会 ID。

    client.on("ready", () => {
    
        // Register global slash command
        client.api.applications(client.user.id).commands.post({
            data: {
                name: "hello",
                description: "Say 'Hello, World!'"
            }
        });
    
        // Listen for an interaction (e.g. user typed command)
        client.ws.on("INTERACTION_CREATE", (interaction) => {
            // Access command properties
            const commandId = interaction.data.id;
            const commandName = interaction.data.name;
            
            // Reply only to commands with name 'hello'
            if (commandName == "hello") {
                // Reply to an interaction
                client.api.interactions(interaction.id, interaction.token).callback.post({
                    data: {
                        type: 4,
                        data: {
                            content: "Hello, World!"
                        }
                    }
                });
            }
        });
    
    });
    

    这是用户使用您的命令的方式:

    回复如下:

    【讨论】:

      猜你喜欢
      • 2021-02-02
      • 1970-01-01
      • 1970-01-01
      • 2021-08-09
      • 2021-11-21
      • 2021-10-10
      • 2021-10-22
      • 2021-06-08
      • 2021-04-21
      相关资源
      最近更新 更多