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

11 messages · Page 1 of 1 (latest)

sage locust
#

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')

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!

lucid shuttleBOT
#
  • 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!
sage locust
#

senderId is the user's id.

hasty jetty
sage locust
#

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?

lethal patio
#

console.log(channel.guild.members.cache.get(senderId)?.permissions)

#

And .permissionsIn(channel)

sage locust
#

channel.guild.members.cache.get(senderId)?.permissions - PermissionsBitField { bitfield: 2248473465835073n }
.permissionsIn(channel) - PermissionsBitField { bitfield: 2248473465834049n }

lethal patio
#

They do have SendMessages permissions. But not ViewChannel

sage locust
#

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?

lethal patio
#

Those two.