如何将Discord机器人的guild斜杠命令转为global commands?
切换Discord机器人命令为全局命令
要把你的服务器专属命令改成全局命令,只需要做两个关键修改:
- 移除代码中指定服务器ID的逻辑,全局命令不需要绑定特定服务器
- 调用命令创建方法时,去掉第二个服务器ID参数
修改后的完整代码如下:
client.once('ready', () => { console.log('All set and ready to go!') const start = new SlashCommandBuilder() .setName('start') .setDescription('Start a new game lobby') .addStringOption(options => options .setName('game') .setDescription('The kind of game you want to start') .setRequired(true) .addChoices( { name: 'Never Have I Ever', value: 'nhie' }, { name: "Would You Rather", value: 'wyr' } ) ) client.application.commands.create(start) const end = new SlashCommandBuilder() .setName('end') .setDescription('Ends the current game') client.application.commands.create(end) })
注意事项
全局命令同步到所有服务器需要约1小时的时间,修改后不要着急测试,等待Discord完成同步即可。如果需要快速验证命令逻辑,可以先用服务器专属命令调试,确认没问题再切换成全局命令。
内容的提问来源于stack exchange,提问作者RRTropical
相关产品推荐
相关产品推荐

