【发布时间】:2022-01-04 08:51:27
【问题描述】:
在这种情况下我的问题不是代码,因为我使用的是最新版本的 discord.js 文档 (v13.3.1) 中的直接代码。我读到我需要在 Discord Developers 门户机器人面板的 OAuth2 设置中检查范围“applications.commands”。
在 OAuth2 > 常规 > 默认授权链接
在授权方法中,我选择了“应用内授权”并检查了“bot”和“applications.commands”范围,因为我正在学习 bot 的权限是“管理员”
在 OAuth2 > GenerateUrl
在此部分中,为了制作邀请链接,我只选择了“Bot”范围,因为当我尝试选择“applications.commands”范围时,Discord 会询问我重定向 URL,在我的情况下,我没有网站,现在我不想创建它,我不确定这是否真的有必要,在这种情况下,我不知道是否有其他方法可以注册 Slash 命令,无论如何,如果有人需要看代码,就是这样:
const { clientId, guildId, token } = require('./config.json');
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(token);
(async () => {
try {
console.log('Started refreshing application (/) commands.');
await rest.put(
Routes.applicationGuildCommands(clientId, guildId),
{ body: commands },
);
console.log('Successfully reloaded application (/) commands.');
} catch (error) {
console.error(error);
}
})();
希望有人能帮帮我,非常感谢。
【问题讨论】:
标签: node.js oauth-2.0 discord discord.js bots