Check if user that sent a message have permission
How can i check if the bot have a specific permission on the server?
I was using
if (msg.member.permissions.has("USE_APPLICATION_COMMANDS"))
but its giving me Cannot read properties of null (reading 'permissions')
31 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![email protected], node v18.17.1
Unknown User•17mo ago
Message Not Public
Sign In & Join Server To View
uh sorry
bot.on('messageCreate', msg => {
Unknown User•17mo ago
Message Not Public
Sign In & Join Server To View
so it should be
if (msg.guild.me.permissions.has("USE_APPLICATION_COMMANDS"))
?Unknown User•17mo ago
Message Not Public
Sign In & Join Server To View
uh sorry, i did a confusion here
with that i meant "check if the user that sent the message have a specific permission on the server"
i did a mistake because my code have both, sorry
Unknown User•17mo ago
Message Not Public
Sign In & Join Server To View
its ran in the general channel of my guild
and i have admin permission enabled
Unknown User•17mo ago
Message Not Public
Sign In & Join Server To View
const bot = new Client({ intents: [Intents.FLAGS.GUILDS, Intents.FLAGS.GUILD_MESSAGES] });
Unknown User•17mo ago
Message Not Public
Sign In & Join Server To View
okay, for clarity (and since the code is huge to paste here), here is my .js file:
https://github.com/vico93/quebra_gelo/blob/default/main.js
it starts on line 27
yeah, i'm using "commands" in the old way, sorry
Unknown User•17mo ago
Message Not Public
Sign In & Join Server To View
how can i do that?
Unknown User•17mo ago
Message Not Public
Sign In & Join Server To View
ah yeah
Unknown User•17mo ago
Message Not Public
Sign In & Join Server To View
okay, sent
should i sent the full output here?
@Jô 🌈 🦄
Unknown User•17mo ago
Message Not Public
Sign In & Join Server To View
yeah
Unknown User•17mo ago
Message Not Public
Sign In & Join Server To View
It's good practice to make your bots ignore other bots, including itself. This can be done through a single line of code:
<message> being whatever you defined message as.
Unknown User•17mo ago
Message Not Public
Sign In & Join Server To View
oh morning
will add the check
wait
shouldn't i change <message>.member to <message>.author ?
just wondering after seeing the snippet for checking if the message author is a bot...
ah, just forget it, i read in the docs that .author and .member return diferent data
@Jô 🌈 🦄 well, i've update the main.js with the logging information you told me to put (plus i logged also
msg.member.permissions
) and added the bot filter the bot putThe first message was me doing
gelo!help
. The second one seems to be the bot returning the command list (since i positioned the bot filtering after the logging)i will move the bot filter to before the logs to see one thing