DiscordAPIerror: Missing Access
So this is the first time I got this error and researching a while I found out this is due to missing permissions. My bot has the viewmessages and sendmessages permissions but still this error has occurred. Can I know how to fix this? I think this is a server specific issue where the permissions were overwritten to revoke viewchannel? If it's something server related and not under the control of the bot how can I tackle this?
9 Replies
- 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!
- ✅
Marked as resolved by OPshow your code
I figured it out actually, why is it happening
It occurs when someone uses the bot in a private channel because it is missing the viewchannels permission and hence it cannot send messages in the channel
Do you know how I can prevent this?
by adding a permission check
:method: TextChannel#permissionsFor
@14.15.3
Gets the overall set of permissions for a member or role in this channel, taking into account channel overwrites.if(interaction.channel.permissionsFor(interaction.guild.roles.everyone).has(PermissionsBitField.Flags.ViewChannel)){
}
ig the check would go something like this correct? but i'm checking this for everyone role, how do i check for the role the bot has?
might be a real amateur question but i never really needed to fetch the bot roles beforeWhy are you checking for everyone role? That doesn't necessarily rules out your bot? Check for you bot's member, use
interaction.guild.members.me
Or get bot's member by using fethMe()
if me
is nullYeah got it! Thanks a lot
I have another question, now since I have put this check it will prevent the bot from crashing but how do I let the user know the problem as the bot can't really send anything
Reply to the interaction, interaction's reply isn't bound by channel (view) permission (unless it's
Use Application Command
)