How can I check if a user id has permission to send messages to a channel?

Hello, I am trying to check if a user has permission to send messages to a channel like this:
const canSpeak = channel.permissionsFor(senderId)?.has('SendMessages')
const canSpeak = channel.permissionsFor(senderId)?.has('SendMessages')
But this seems to always return true even when it shouldn't. Are there some intents I need to enable, and is this the wrong way to do this? I just need a basic way to tell if they should be able to chat in the channel. Could I just check if they are a member of the channel? I haven't used Discord all that much but I feel like it is possible to be a member of a channel yet still not have permission to chat in it. I would also like to know how to do this for reading messages/reading message history. Thank you!
4 Replies
d.js toolkit
d.js toolkit3w 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!
trevdev
trevdev3w ago
senderId is the user's id.
xx_lavaboy_xx123
this code is correct so you're either passing wrong user id or the member has perms to send messages in that channel, how is senderId defined?
trevdev
trevdev2w ago
To my knowledge the senderId should be accurate. i logged the value and checked that it was right. also the channel is private, and the user is not in it. yet it still returns true. could there be another problem? channel.guild.members.cache.get(senderId)?.permissions - PermissionsBitField { bitfield: 2248473465835073n } .permissionsIn(channel) - PermissionsBitField { bitfield: 2248473465834049n } Ok great thank you that makes sense. If I want to check that any given player has permission to send messages in a channel and also check if they can read the messages in a channel, what permissions do I check? Are there any caveats I should watch out for?
Want results from more Discord servers?
Add your server
More Posts