'how to fix errors like this "DiscordAPIError: Missing Access"
I followed the tutorial from youtube and I found an error like this and I don't know where the problem is. When i run node my_bot.js, Then there is an error DiscordAPIError: Missing Access.
I've tried a few things. My expectation will appear the words Hello World on discord. The result is an error.
I think, there is nothing wrong with my code
const { Client, Intents } = require('discord.js');
const client = new Client({ intents: [Intents.FLAGS.GUILDS, Intents.FLAGS.GUILD_MESSAGES] });
client.on('ready', () => {
console.log("Connected as " + client.user.tag)
client.user.setActivity('you', { type: 'WATCHING' });
client.guilds.cache.forEach((guild) => {
console.log(guild.name);
guild.channels.cache.forEach((channel) => {
console.log(` - ${channel.name} ${channel.type} ${channel.id}`)
})
// General channel id: 956453625889185826
})
let generalChannel = client.channels.cache.get("956453625889185826")
generalChannel.send("Hello World")
})
client.login("XXXXXXXXXXXXXXXXXXXXX")
Result:
Connected as Davd#3016
gavbot
- Text Channels GUILD_CATEGORY 956453625889185824
- Voice Channels GUILD_CATEGORY 956453625889185825
- general GUILD_TEXT 956453625889185826
- General GUILD_VOICE 956453625889185827
C:\Users\User\node_modules\discord.js\src\rest\RequestHandler.js:350
throw new DiscordAPIError(data, res.status, request);
^
DiscordAPIError: Missing Access
at RequestHandler.execute (C:\Users\User\node_modules\discord.js\src\rest\RequestHandler.js:350:13)
at processTicksAndRejections (node:internal/process/task_queues:96:5)
at async RequestHandler.push (C:\Users\User\node_modules\discord.js\src\rest\RequestHandler.js:51:14)
at async TextChannel.send (C:\Users\User\node_modules\discord.js\src\structures\interfaces\TextBasedChannel.js:175:15) {
method: 'post',
path: '/channels/956453625889185826/messages',
code: 50001,
httpStatus: 403,
requestData: {
json: {
content: 'Hello World',
tts: false,
nonce: undefined,
embeds: undefined,
components: undefined,
username: undefined,
avatar_url: undefined,
allowed_mentions: undefined,
flags: undefined,
message_reference: undefined,
attachments: undefined,
sticker_ids: undefined
},
files: []
}
}
Solution 1:[1]
As the error says, Missing access means that your bot doesn't have the permissions to send a message in the channel.
Make sure your bot has the Send message permission in the channel you want to send the message
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | Pythonwolf |
