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

16 messages · Page 1 of 1 (latest)

twin nimbus
#

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}.`
    );
}

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

bright etherBOT
#
  • What's your exact discord.js npm list discord.js and node node -v version?
  • Not a discord.js issue? Check out #1081585952654360687.
  • 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!
keen saffron
#

also you can use the permission flags bits to avoid that type assertion

past pagodaBOT
twin nimbus
keen saffron
#

.has(PermissionFlagsBits.SendMessages) instead of your current .has()

hoary canopy
#

Your current code in the post should work without the cast too though

twin nimbus
# keen saffron you also need ViewChannel

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

gilded crane
twin nimbus
#

the bot doesn't attempt to send messages in threads though

#

just in channels

#

but i can add that permission in just in case

gilded crane
#

Do you know that for certain?

twin nimbus
#

like 90% sure. but i'll check for that permission too in case i'm misremembering

gilded crane
#

You could try adding some debugging too. Log the channel (so you know what type it is) and log your permissions to see what you have for the channel. Should help you figure out what's going on