PERMISIONS BITFIELD

someone has an idea how to write it better and also make this thing work? im checking for names instead of bitfield and I need to return a string at the end of the day to let the user know what permissions are missing:
const requiredPermissions = [
PermissionsBitField.Flags.ViewChannel,
PermissionsBitField.Flags.ManageChannels,
PermissionsBitField.Flags.ManageRoles,
PermissionsBitField.Flags.SendMessages,
PermissionsBitField.Flags.EmbedLinks
];
const botPermissions = interaction.guild.members.me.permissions;
const missingPermissions = requiredPermissions.filter(permission => !botPermissions.has(permission));
const missingPermissionNames = missingPermissions.map(permission=>{
switch (permission) {
case PermissionsBitField.Flags.ViewChannel:
return 'View Channels';
case PermissionsBitField.Flags.ManageChannels:
return 'Manage Channels';
case PermissionsBitField.Flags.ManageRoles:
return 'Manage Roles';
case PermissionsBitField.Flags.SendMessages:
return 'Send Messages';
case PermissionsBitField.Flags.EmbedLinks:
return 'Embed Links';
default:
return 'Unknown Permission';
}
});
const requiredPermissions = [
PermissionsBitField.Flags.ViewChannel,
PermissionsBitField.Flags.ManageChannels,
PermissionsBitField.Flags.ManageRoles,
PermissionsBitField.Flags.SendMessages,
PermissionsBitField.Flags.EmbedLinks
];
const botPermissions = interaction.guild.members.me.permissions;
const missingPermissions = requiredPermissions.filter(permission => !botPermissions.has(permission));
const missingPermissionNames = missingPermissions.map(permission=>{
switch (permission) {
case PermissionsBitField.Flags.ViewChannel:
return 'View Channels';
case PermissionsBitField.Flags.ManageChannels:
return 'Manage Channels';
case PermissionsBitField.Flags.ManageRoles:
return 'Manage Roles';
case PermissionsBitField.Flags.SendMessages:
return 'Send Messages';
case PermissionsBitField.Flags.EmbedLinks:
return 'Embed Links';
default:
return 'Unknown Permission';
}
});
3 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
:method: PermissionsBitField#missing() @14.16.2 Gets all given bits that are missing from the bitfield.
Shahar
ShaharOP2mo ago
@Qjuh
const requiredPermissions = new PermissionsBitField([
PermissionsBitField.Flags.ViewChannel,
PermissionsBitField.Flags.ManageChannels,
PermissionsBitField.Flags.ManageRoles,
PermissionsBitField.Flags.SendMessages,
PermissionsBitField.Flags.EmbedLinks]);

const botPermissions = interaction.guild.members.me.permissions.missing(requiredPermissions);
const requiredPermissions = new PermissionsBitField([
PermissionsBitField.Flags.ViewChannel,
PermissionsBitField.Flags.ManageChannels,
PermissionsBitField.Flags.ManageRoles,
PermissionsBitField.Flags.SendMessages,
PermissionsBitField.Flags.EmbedLinks]);

const botPermissions = interaction.guild.members.me.permissions.missing(requiredPermissions);
did I use it right cuz i get nothing also do i need to fetch the members to get the most updated permissions? like just empty string I guess might be need await? simply consolelog it ohh now I got empty array, its because I tried to parse it to string although the bot got
PermissionsBitField.Flags.ViewChannel, PermissionsBitField.Flags.ManageChannels, PermissionsBitField.Flags.ManageRoles, those permissions in his role but sendmessahes and embedlinks he doesnt have checking good point thank you very much it worked
Want results from more Discord servers?
Add your server