在discord.js v13中,可以使用以下代码在特定的服务器上注册全局命令:
const { REST } = require('@discordjs/rest');
const { Routes } = require('discord-api-types/v9');
const commands = [{
name: 'ping',
description: 'Replies with Pong!'
}]; // 命令的具体内容,可自定义
const rest = new REST({ version: '9' }).setToken('YOUR_TOKEN');
rest.put(Routes.applicationGuildCommands('APP_ID', 'GUILD_ID'), { body: commands })
.then(() => console.log('Registered guild commands'))
.catch(console.error);
其中APP_ID
和GUILD_ID
为Discord应用程序ID和服务器ID,可以在Discord开发者门户中找到。这将在特定的服务器上注册全局命令。如果想在所有服务器上部署全局命令,可以使用Routes.applicationCommands()
来替代Routes.applicationGuildCommands('APP_ID', 'GUILD_ID')
。
上一篇:Applicationgatewayrewriterule,remove/attheendofurl
下一篇:applicationhost.config中的http谓词RequestFiltering值可以在我的网站中重写吗?