DiscordAPIError[50001]: Missing Access, likely due to missing "send messages" permissions

Hi everyone! This is an error that I get approximately every few days for my 1500+ servers bot: https://pastebin.com/mpqvFGZz I suspect that this is occurring because the bot is trying to send a message in a channel that hasn't given it send messages permissions. I try to handle this case in my code with 2 ways: one with a universal try-catch that just prints the error and doesn't error out (which obviously doesn't work) and another like so:
if (
!streamChannel.isDMBased() &&
!streamChannel
.permissionsFor(botGuildMember)
?.has("SendMessages" as PermissionResolvable)
) {
return await channel.send(
`:x: I do not have permission to send messages in ${streamChannel.name}.`
);
}
if (
!streamChannel.isDMBased() &&
!streamChannel
.permissionsFor(botGuildMember)
?.has("SendMessages" as PermissionResolvable)
) {
return await channel.send(
`:x: I do not have permission to send messages in ${streamChannel.name}.`
);
}
in this case, channel is the original channel in which an interaction was initialized, and streamChannel is another channel in the server that the bot is, later on, attempting to send a message in. However, I'm not sure why, but this logic doesn't work either, and I'm not sure why. Any ideas? discord.js veresion: 14.14.1
Pastebin
DiscordAPIError[50001]: Missing Access at handleErrors (/app/nod...
Pastebin.com is the number one paste tool since 2002. Pastebin is a website where you can store text online for a set period of time.
7 Replies
d.js toolkit
d.js toolkit3mo ago
- What's your exact discord.js npm list discord.js and node node -v version? - Not a discord.js issue? Check out #other-js-ts. - Consider reading #how-to-get-help to improve your question! - Explain what exactly your issue is. - Post the full error stack trace, not just the top part! - Show your code! - Issue solved? Press the button!
Amgelo
Amgelo3mo ago
you also need ViewChannel also you can use the permission flags bits to avoid that type assertion
d.js docs
d.js docs3mo ago
:dtypes: v10: PermissionFlagsBits read more
harbar20
harbar20OP3mo ago
how do you mean? not sure i understand
Amgelo
Amgelo3mo ago
.has(PermissionFlagsBits.SendMessages) instead of your current .has()
harbar20
harbar20OP3mo ago
after adding this permission I'm still getting the same error instead of it failing out. could there be other causes? if there aren't any I'll remove the global try catch and see if it helps the bot doesn't attempt to send messages in threads though just in channels but i can add that permission in just in case like 90% sure. but i'll check for that permission too in case i'm misremembering
Amgelo
Amgelo3mo ago
threads are also channels btw

Did you find this page helpful?