Returning bot's missing permissions

Hey, i made a function, which is supposed to check for the missing permissionsn in the array of permissions i give it. Instead, it either returns all permissions, or no permissions at all. Code for function: https://srcb.in/8ylqAtQbhb How i utilize the function: https://srcb.in/Jlacln3RD9 Permissions for the channel i'm checking in (Thread channel): pic attached How the bot responds: pic attached
SourceBin
Function
Instantly share your code with the world.
SourceBin
Function
Instantly share your code with the world.
No description
No description
6 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!
Syjalo
Syjalo11mo ago
1. I don't see the point of checking both global and channel specific permissions. A permission can be allowed globally, but denied in the channel. Your code does wrong thing. 2. permissions.has((a || b) && c) checks if (a or b) and c has in the permissions (means one of). You need to check (permissions.has(a) || permissions.has(b)) && permissions.has(c). 3. Your returnMissingPermissions does a lot of unnecessary things. You can just filter permissions, map by keys adding the formatting and then join the array.
d.js docs
d.js docs11mo ago
method PermissionsBitField#missing() Gets all given bits that are missing from the bitfield.
zeyad
zeyadOP11mo ago
alright i was testing a bit with this function. this is my function now (for testing):
function returnMissingPermissions(permissions: PermissionsBitField) {
console.log(permissions.missing(perms));
}
function returnMissingPermissions(permissions: PermissionsBitField) {
console.log(permissions.missing(perms));
}
this is how i call my function:
returnMissingPermissions(permissions)
returnMissingPermissions(permissions)
where permissions is:
const permissions = new PermissionsBitField();
permissions.add(perms);
const permissions = new PermissionsBitField();
permissions.add(perms);
and perms is:
const perms = [
PermissionsBitField.Flags.CreatePublicThreads,
PermissionsBitField.Flags.CreatePrivateThreads,
PermissionsBitField.Flags.SendMessagesInThreads,
PermissionsBitField.Flags.SendMessages,
];
const perms = [
PermissionsBitField.Flags.CreatePublicThreads,
PermissionsBitField.Flags.CreatePrivateThreads,
PermissionsBitField.Flags.SendMessagesInThreads,
PermissionsBitField.Flags.SendMessages,
];
however, the log is an emtpy array
zeyad
zeyadOP11mo ago
these are my perms btw
No description
zeyad
zeyadOP10mo ago
Isn't the function supposed to check which permissions from the array perms is missing from permissions the bot has (which is permissions)? WAIT oh I thought I was passing the bot's permissions let me edit the code
returnMissingPermissions((await interaction.guild?.members.fetchMe())?.permissions as PermissionsBitField)
returnMissingPermissions((await interaction.guild?.members.fetchMe())?.permissions as PermissionsBitField)
this is how i now call my function still logging an empty array alright so to test this, i denied the everyone role the perms, and now it's logging the 3 perms missing. So now i believe i'm supposed to check for both, instead of checking only for channel permission overwrites alright tysm okay tysm Okay it's a bit late, but i've now edited the code, to check for permissionsOverwrites. When i allow the Create Posts permissions on the channel, both CreatePrivateThreads and CreatePublicThreads return as missing and the permission SendMessages (not SendMessagesInThreads) passes (doesn't return as missing) even though when that permission in the channel was denied, it was returned missing This is the function:
function returnMissingPermissions(permissions: PermissionsBitField) {
const $ = permissions
.missing([
PermissionsBitField.Flags.CreatePublicThreads,
PermissionsBitField.Flags.CreatePrivateThreads,
PermissionsBitField.Flags.SendMessagesInThreads,
PermissionsBitField.Flags.SendMessages,
])
.toString()
.replace(/[A-Z]/g, ' $&')
.slice(1)
.split(', ')
.map(string => string.replace(string, `* **${string}**`))
.join('\n');

console.log($);
return $;
}
function returnMissingPermissions(permissions: PermissionsBitField) {
const $ = permissions
.missing([
PermissionsBitField.Flags.CreatePublicThreads,
PermissionsBitField.Flags.CreatePrivateThreads,
PermissionsBitField.Flags.SendMessagesInThreads,
PermissionsBitField.Flags.SendMessages,
])
.toString()
.replace(/[A-Z]/g, ' $&')
.slice(1)
.split(', ')
.map(string => string.replace(string, `* **${string}**`))
.join('\n');

console.log($);
return $;
}
and this is how i call it:
const botPermissions = channel.permissionsFor(
(await interaction.guild?.members.fetchMe()) as GuildMember,
);
returnMissingPermissions(botPermissions)
const botPermissions = channel.permissionsFor(
(await interaction.guild?.members.fetchMe()) as GuildMember,
);
returnMissingPermissions(botPermissions)
what about Send messages in posts permission?
Want results from more Discord servers?
Add your server