gpt4 book ai didi

javascript - Discord JS - DiscordAPIError : Missing Access

转载 作者:行者123 更新时间:2023-12-05 00:30:17 32 4
gpt4 key购买 nike

So i follow worn off keys tutorial to discord bot and i don't know what the problem is, here is the error

/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: []
}
}
我也尝试查看我的代码,但我没有发现有什么问题。

This is my code, I really think something is wrong in the code.

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)

最佳答案

对于任何有同样问题的人。我通过简单地转到机器人开发者门户然后转到 OAuth2 > URL 生成器来解决此问题。对于范围,选择“bot”和“applications.commands”。然后向下滚动选择您的机器人需要复制 URL 的任何权限。

关于javascript - Discord JS - DiscordAPIError : Missing Access,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/69833215/

32 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com