Permissions

is there a way to know what permissions my bot has in a specific channel? (ignoring the role permissions he has when we got to the guild) because when I use interaction.channel.permissionsFor(interaction.guild.members.me) returns the combined permissions he has in role perspective and channel
8 Replies
d.js toolkit
d.js toolkit2mo 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!
d.js docs
d.js docs2mo ago
:property: PermissionOverwriteManager#cache @14.16.2 The cache of items for this manager.
duck
duck2mo ago
if you're looking to just check permission overwrites, you'd want to parse <GuildChannel>.permissionOverwrites.cache if you're just looking for an overwrite explicitly for the client member, you can just use ...cache.get() since the overwrite id is the member/role's id
Shahar
ShaharOP2mo ago
im looking to just simply check if he has the necessary permissions within the specific channel the interaction came from (in my case guild channel that is a voice channel type) or just check if the permissions for him is exists specificly. cache will be updated live? should i fetch it?
duck
duck2mo ago
on the assumption you have the Guilds intent, it would be up to date that being said, I'm not really sure what you'd need to differentiate between overwrites and accumulated permissions for
Shahar
ShaharOP2mo ago
yea, so even if there is no role in the channel of my bot. it still returns the permissions he got in (everyone + bot role in guild). And I need to check for the channel permissions
const botPermissions = interaction.guild.members.me.permissionsIn(interaction.channel)
console.log(botPermissions);
const botMissingPermissions = botPermissions.has(channelPermissions);
console.log(botMissingPermissions);
if(!botPermissions.has(channelPermissions)){
channelPermissionErrorEmbedMessage(interaction);
return;
}
const botPermissions = interaction.guild.members.me.permissionsIn(interaction.channel)
console.log(botPermissions);
const botMissingPermissions = botPermissions.has(channelPermissions);
console.log(botMissingPermissions);
if(!botPermissions.has(channelPermissions)){
channelPermissionErrorEmbedMessage(interaction);
return;
}
is there a way to check if he has permission overwrite within a channel? thanks. I will give it a try yea so, I give him the following list of permissions in guild role:
PermissionsBitField.Flags.ViewChannel,
PermissionsBitField.Flags.ManageChannels,
PermissionsBitField.Flags.ManageRoles,
PermissionsBitField.Flags.ManageWebhooks,
PermissionsBitField.Flags.SendMessages,
PermissionsBitField.Flags.EmbedLinks,
PermissionsBitField.Flags.ManageMessages,
PermissionsBitField.Flags.ReadMessageHistory,
PermissionsBitField.Flags.Connect,
PermissionsBitField.Flags.MoveMembers
PermissionsBitField.Flags.ViewChannel,
PermissionsBitField.Flags.ManageChannels,
PermissionsBitField.Flags.ManageRoles,
PermissionsBitField.Flags.ManageWebhooks,
PermissionsBitField.Flags.SendMessages,
PermissionsBitField.Flags.EmbedLinks,
PermissionsBitField.Flags.ManageMessages,
PermissionsBitField.Flags.ReadMessageHistory,
PermissionsBitField.Flags.Connect,
PermissionsBitField.Flags.MoveMembers
but still I need to add for the channel his role with the following:
PermissionsBitField.Flags.ViewChannel,
PermissionsBitField.Flags.ManageChannels,
PermissionsBitField.Flags.Connect,
PermissionsBitField.Flags.ViewChannel,
PermissionsBitField.Flags.ManageChannels,
PermissionsBitField.Flags.Connect,
in order for him to function with my current behivor yep, thats exactly right, im changing the everyone role hmm, still it should make it returned but it didnt Like he continue becuase he "has" the permissions, but infact the bot is throwing error missing permissions. when he does have the role in the channel its not throwing any error
d.js docs
d.js docs2mo ago
:property: CommandInteraction#appPermissions @14.16.2 Set of permissions the application or bot has within the channel the interaction was sent from
Shahar
ShaharOP2mo ago
I hope I've explained it well, its kinda complicated messing with the permissions true, thats exactly what I need but for a button interaction oh nice, thank you very much still didn't work, when everyone is on "null" and there is no permissions for the bot in the channel he doesnt have the neseccery perms. code:
const botPermissions = interaction.appPermissions
console.log(botPermissions);
if(!botPermissions.has(channelPermissions)){
channelPermissionErrorEmbedMessage(interaction);
return;
}
const botPermissions = interaction.appPermissions
console.log(botPermissions);
if(!botPermissions.has(channelPermissions)){
channelPermissionErrorEmbedMessage(interaction);
return;
}
output:
PermissionsBitField {bitfield: 140742606547984n}

DiscordAPIError[50001]: Missing Access
at handleErrors (C:\Users\Shahar Gutman\Desktop\node_modules\@discordjs\rest\dist\index.js:727:13)
at process.processTicksAndRejections (node:internal/process/task_queues:95:5)
at async SequentialHandler.runRequest (C:\Users\Shahar Gutman\Desktop\node_modules\@discordjs\rest\dist\index.js:1128:23)
at async SequentialHandler.queueRequest (C:\Users\Shahar Gutman\Desktop\node_modules\@discordjs\rest\dist\index.js:959:14)
at async _REST.request (C:\Users\Shahar Gutman\Desktop\node_modules\@discordjs\rest\dist\index.js:1272:22)
at async GuildMessageManager.edit (C:\Users\Shahar Gutman\Desktop\node_modules\discord.js\src\managers\MessageManager.js:188:15)
at async updateChannelPrimalMessage (C:\Users\Shahar Gutman\Desktop\events\ChannelUpdate.js:142:3)
at async checkNewState (C:\Users\Shahar Gutman\Desktop\events\ChannelUpdate.js:94:5)
at async Object.execute (C:\Users\Shahar Gutman\Desktopevents\ChannelUpdate.js:36:2) {requestBody: {…}, rawError: {…}, code: 50001, status: 403, method: 'PATCH', …}
PermissionsBitField {bitfield: 140742606547984n}

DiscordAPIError[50001]: Missing Access
at handleErrors (C:\Users\Shahar Gutman\Desktop\node_modules\@discordjs\rest\dist\index.js:727:13)
at process.processTicksAndRejections (node:internal/process/task_queues:95:5)
at async SequentialHandler.runRequest (C:\Users\Shahar Gutman\Desktop\node_modules\@discordjs\rest\dist\index.js:1128:23)
at async SequentialHandler.queueRequest (C:\Users\Shahar Gutman\Desktop\node_modules\@discordjs\rest\dist\index.js:959:14)
at async _REST.request (C:\Users\Shahar Gutman\Desktop\node_modules\@discordjs\rest\dist\index.js:1272:22)
at async GuildMessageManager.edit (C:\Users\Shahar Gutman\Desktop\node_modules\discord.js\src\managers\MessageManager.js:188:15)
at async updateChannelPrimalMessage (C:\Users\Shahar Gutman\Desktop\events\ChannelUpdate.js:142:3)
at async checkNewState (C:\Users\Shahar Gutman\Desktop\events\ChannelUpdate.js:94:5)
at async Object.execute (C:\Users\Shahar Gutman\Desktopevents\ChannelUpdate.js:36:2) {requestBody: {…}, rawError: {…}, code: 50001, status: 403, method: 'PATCH', …}
he is tryin to edit a message but he has no permissions Yes The bot is adding to its self the permissions overwrites at a certain point. And if a user will remove it , it will cause issues to my bot. So I want to check at any time if he has it, if not just return a message But it’s not checking it properly I want to relate only to the channels and it doesn’t Like to relate to my bot permissions in a specific channel where the interaction came from as I mentioned Exactly right That is way I need to check only the bot permission overwrite in the channel I guess @Qjuh that was the solution, using permissionOverwrite, thank you very much for your help. @duck btw I do need to fetch the channel in order for the cache to be updated, I got accross some issues if I dont fetch it which its not updated, so I do fetch everytime altough its slower I am messing with sweepers maybe that’s why
sweepers: {
...Options.DefaultSweeperSettings,
messages: {
interval: 3600,
lifetime: 3600,
},
users: {
interval: 46400,
filter: () => user => user.id !== client.user.id
},
}
sweepers: {
...Options.DefaultSweeperSettings,
messages: {
interval: 3600,
lifetime: 3600,
},
users: {
interval: 46400,
filter: () => user => user.id !== client.user.id
},
}
Want results from more Discord servers?
Add your server