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
d.js toolkit
d.js toolkit11mo 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!
Vico
Vico11mo ago
discord.js@13.16.0, node v18.17.1
Unknown User
Unknown User11mo ago
Message Not Public
Sign In & Join Server To View
Vico
Vico11mo ago
uh sorry bot.on('messageCreate', msg => {
Unknown User
Unknown User11mo ago
Message Not Public
Sign In & Join Server To View
d.js docs
d.js docs11mo ago
property Guild#me DEPRECATED The client user as a GuildMember of this guild
Vico
Vico11mo ago
so it should be if (msg.guild.me.permissions.has("USE_APPLICATION_COMMANDS"))?
Unknown User
Unknown User11mo ago
Message Not Public
Sign In & Join Server To View
Vico
Vico11mo ago
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
Unknown User11mo ago
Message Not Public
Sign In & Join Server To View
Vico
Vico11mo ago
its ran in the general channel of my guild and i have admin permission enabled
Unknown User
Unknown User11mo ago
Message Not Public
Sign In & Join Server To View
Vico
Vico11mo ago
const bot = new Client({ intents: [Intents.FLAGS.GUILDS, Intents.FLAGS.GUILD_MESSAGES] });
Unknown User
Unknown User11mo ago
Message Not Public
Sign In & Join Server To View
Vico
Vico11mo ago
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
Unknown User11mo ago
Message Not Public
Sign In & Join Server To View
Vico
Vico11mo ago
how can i do that?
Unknown User
Unknown User11mo ago
Message Not Public
Sign In & Join Server To View
Vico
Vico11mo ago
ah yeah
Unknown User
Unknown User11mo ago
Message Not Public
Sign In & Join Server To View
Vico
Vico11mo ago
okay, sent should i sent the full output here?
Vico
Vico11mo ago
Vico
Vico11mo ago
@Jô 🌈 🦄
Unknown User
Unknown User11mo ago
Message Not Public
Sign In & Join Server To View
Vico
Vico11mo ago
yeah
Unknown User
Unknown User11mo ago
Message Not Public
Sign In & Join Server To View
d.js docs
d.js docs11mo ago
It's good practice to make your bots ignore other bots, including itself. This can be done through a single line of code:
if (<message>.author.bot) return;
if (<message>.author.bot) return;
<message> being whatever you defined message as.
Unknown User
Unknown User11mo ago
Message Not Public
Sign In & Join Server To View
Vico
Vico11mo ago
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 put
Vico
Vico11mo ago
The 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)
Vico
Vico11mo ago
i will move the bot filter to before the logs to see one thing