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
- 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!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
<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)Do you have the
GuildMembers
intent?Yes
Can you try using
(await <Message/interaction>.guild.members.fetchMe()).permissions
instead?(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')
That’s interesting, do you have partials enabled?
Idk how to enable partials in @discordjs/core (@discordjs/ws))
Oh, you’re using /core?
yes
Then disregard everything I said before
anyway, thx for help)
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
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 existif you're using /core, you'll want to familiarize yourself with and reference the discord docs directly