javascript - Discord JS - DiscordAPIError:缺少访问权限
问题描述
所以我按照不和谐机器人的磨损钥匙教程,我不知道问题是什么,这是错误
/home/container/node_modules/discord.js/src/rest/RequestHandler.js:349
throw new DiscordAPIError(data, res.status, request);
^
DiscordAPIError: Missing Access
at RequestHandler.execute (/home/container/node_modules/discord.js/src/rest/RequestHandler.js:349:13)
at processTicksAndRejections (node:internal/process/task_queues:96:5)
at async RequestHandler.push (/home/container/node_modules/discord.js/src/rest/RequestHandler.js:50:14)
at async GuildApplicationCommandManager.create (/home/container/node_modules/discord.js/src/managers/ApplicationCommandManager.js:117:18) {
method: 'post',
path: '/applications/901999677011005472/guilds/905266476573950023/commands',
code: 50001,
httpStatus: 403,
requestData: {
json: {
name: 'ping',
description: 'Bot uptime/latency checker.',
type: undefined,
options: undefined,
default_permission: undefined
},
files: []
}
}
我也尝试查看我的代码,但我没有发现有什么问题。
这是我的代码,我真的认为代码有问题。
const DiscordJS = require('discord.js')
const { Intents } = require('discord.js')
const dotenv = require('dotenv')
dotenv.config()
const client = new DiscordJS.Client({
intents: [
Intents.FLAGS.GUILDS,
Intents.FLAGS.GUILD_MESSAGES
]
})
client.on('ready', () => {
console.log("The bot is online")
// Carlos: 883425101389914152
const guildId = '905266476573950023'
const guild = client.guilds.cache.get(guildId)
let commands
if (guild) {
commands = guild.commands
} else {
commands = client.application.commands
}
commands.create({
name: 'ping',
description: 'Bot uptime/latency checker.',
})
commands.create({
name: 'add',
description: 'Adds two numbers given by user.',
options: [
{
name: 'number1',
description: 'The first number',
required: true,
type: DiscordJS.Constants.ApplicationCommandOptionTypes.NUMBER,
},
{
name: 'number2',
description: 'The second number',
required: true,
type: DiscordJS.Constants.ApplicationCommandOptionTypes.NUMBER,
},
]
})
})
client.on('interactionCreate', async (interaction) => {
if (!interaction.isCommand()) {
return
}
const { commandName, Options } = interaction
if (commandName === 'ping') {
interaction.reply({
content: 'Pong! **60ms**',
// If anyone can see = True, Only command user can see = False
ephemeral: true,
})
} else if (commandName === 'add') {
interaction.reply({
content: 'The sum is ${number1 + number2}'
})
}
})
client.login(process.env.KEY)
解决方案
为您的不和谐服务器创建机器人登录链接时,您没有选择正确的权限。
再次转到开发人员/oauth,单击机器人并选择您在此机器人中使用的所有必需权限。
然后复制生成的链接并使用它通过您的机器人登录到您的服务器。
推荐阅读
- python - 如何使用 selenium 将网页滚动到目标元素
- java - Android 应用程序未从 Socket 输入流中读取
- sql - Oracle——创建基于游标删除表的动态函数
- python - 使用文件对象将 json 列表压缩为 Gzip
- markdown - 如何阻止 pandoc 转义字符?
- python - 如何自然地对“WindowsPath”对象文件进行排序
- c - 浮点数在我的 C 程序中未正确显示
- r - Docker闪亮服务器自动进入示例欢迎页面
- node.js - 如何使用 react axios 和 node js fs.unlinkSync 删除本地存储中的图像或文件
- python - 如何使用 lxml 删除 XML 文档根元素之外的注释