How can I check the permissions in @discordjs/core

How can I check the permissions of my bot & the member who sent the message (or interacted with a component) in the handler of the corresponding event?
17 Replies
d.js toolkit
d.js toolkit14mo 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!
lupus
lupus14mo ago
Given that the interaction/message was sent while in a guild (you might have to check that when handling the event), you can use <Message>/<Interaction>.member.permissions and <Message/Interaction>.guild.members.me.permissions
xf52
xf52OP14mo ago
<Message>.member.permissions returns undefined; <Message>.guild.members.me.permissions returns TypeError: Cannot read properties of undefined (reading 'members') <Interaction>.guild.members.me.permissions returns TypeError: Cannot read properties of undefined (reading 'me') <Interaction>.member.permissions returns 562949953421311 (contains a valid value)
lupus
lupus14mo ago
Do you have the GuildMembers intent?
xf52
xf52OP14mo ago
Yes
lupus
lupus14mo ago
Can you try using (await <Message/interaction>.guild.members.fetchMe()).permissions instead?
xf52
xf52OP14mo ago
(await <Message>.guild.members.fetchMe()).permissions returns TypeError: Cannot read properties of undefined (reading 'members') (await <Interaction>.guild.members.fetchMe()).permissions returns TypeError: Cannot read properties of undefined (reading 'fetchMe')
lupus
lupus14mo ago
That’s interesting, do you have partials enabled?
xf52
xf52OP14mo ago
Idk how to enable partials in @discordjs/core (@discordjs/ws))
lupus
lupus14mo ago
Oh, you’re using /core?
xf52
xf52OP14mo ago
yes
lupus
lupus14mo ago
Then disregard everything I said before
xf52
xf52OP14mo ago
anyway, thx for help)
lupus
lupus14mo ago
I'm not really familiar with /core and I can't seem to find the appropriate things in the documentation, so you probably have to wait for someone else
duck
duck14mo ago
discord sends <APIInteraction>.app_permissions as the resolved permissions of the bot in the interaction's channel if you want to check permissions similar to the main lib's <Interaction>.guild.members.me.permissions, you'd need to setup some caching of your own for roles and members <APIInteractionGuildMember>.permissions only exists in interaction payloads, so <APIInteraction>.member.permissions will exist
d.js docs
d.js docs14mo ago
discord Receiving and Responding: Interactions > Interaction Object read more
duck
duck14mo ago
if you're using /core, you'll want to familiarize yourself with and reference the discord docs directly
Want results from more Discord servers?
Add your server