How to I turn Permission numbers into a string / array?

const directories = [
...new Set(interaction.client.commands.map((cmd) => cmd.folder)),
];

const formatString = (str) =>
`${str[0].toUpperCase()}${str.slice(1).toLowerCase()}`;

const categories = directories.map((dir) => {
const getCommands = interaction.client.commands
.filter((cmd) => cmd.folder === dir)
.map((cmd) => {
return {
name: cmd.data.name,
description:
cmd.data.description ||
"There is no description for this command.",
--> defaultMemberPermissions: cmd.data.default_member_permissions// || "There are no defualt member permissions for this command"
};
const directories = [
...new Set(interaction.client.commands.map((cmd) => cmd.folder)),
];

const formatString = (str) =>
`${str[0].toUpperCase()}${str.slice(1).toLowerCase()}`;

const categories = directories.map((dir) => {
const getCommands = interaction.client.commands
.filter((cmd) => cmd.folder === dir)
.map((cmd) => {
return {
name: cmd.data.name,
description:
cmd.data.description ||
"There is no description for this command.",
--> defaultMemberPermissions: cmd.data.default_member_permissions// || "There are no defualt member permissions for this command"
};
defaultMemberPermissions returns with a number. How do i make this a string, such as administrator?
3 Replies
d.js toolkit
d.js toolkit2y ago
• What's your exact discord.js npm list discord.js and node node -v version? • Post the full error stack trace, not just the top part! • Show your code! • Explain what exactly your issue is. • Not a discord.js issue? Check out #useful-servers.
d.js docs
d.js docs2y ago
class PermissionsBitField (extends BitField) Data structure that makes it easy to interact with a permission bitfield. All GuildMembers have a set of permissions in their guild, and each channel in the guild may also have PermissionOverwrites for the member that override their default permissions.
PAdventures
PAdventuresOP2y ago
which method should i use? i've tried using most of them and all return the following error:
/Users/NAME/Desktop/Yara/Commands/Info/help.js:41
defaultMemberPermissions: cmd.data.default_member_permissions.serialize()// || "There are no defualt member permissions for this command"
^

TypeError: cmd.data.default_member_permissions.serialize is not a function
at /Users/NAME/Desktop/Yara/Commands/Info/help.js:41:78
at /Users/NAME/Desktop/Yara/node_modules/@discordjs/collection/dist/index.js:239:14
at Function.from (<anonymous>)
at Collection.map (/Users/NAME/Desktop/Yara/node_modules/@discordjs/collection/dist/index.js:237:18)
at /Users/NAME/Desktop/Yara/Commands/Info/help.js:35:12
at Array.map (<anonymous>)
at Object.execute (/Users/NAME/Desktop/Yara/Commands/Info/help.js:32:38)
at Object.execute (/Users/NAME/Desktop/Yara/Events/Interactions/interactionCreate.js:42:21)
at Client.<anonymous> (/Users/NAME/Desktop/Yara/Handlers/eventHandler.js:29:67)
at Client.emit (node:events:524:35)
at InteractionCreateAction.handle (/Users/NAME/Desktop/Yara/node_modules/discord.js/src/client/actions/InteractionCreate.js:97:12)
at module.exports [as INTERACTION_CREATE] (/Users/NAME/Desktop/Yara/node_modules/discord.js/src/client/websocket/handlers/INTERACTION_CREATE.js:4:36)
at WebSocketManager.handlePacket (/Users/NAME/Desktop/Yara/node_modules/discord.js/src/client/websocket/WebSocketManager.js:352:31)
at WebSocketShard.onPacket (/Users/NAME/Desktop/Yara/node_modules/discord.js/src/client/websocket/WebSocketShard.js:494:22)
at WebSocketShard.onMessage (/Users/NAME/Desktop/Yara/node_modules/discord.js/src/client/websocket/WebSocketShard.js:328:10)
at callListener (/Users/NAME/Desktop/Yara/node_modules/ws/lib/event-target.js:290:14)

Node.js v19.8.1
/Users/NAME/Desktop/Yara/Commands/Info/help.js:41
defaultMemberPermissions: cmd.data.default_member_permissions.serialize()// || "There are no defualt member permissions for this command"
^

TypeError: cmd.data.default_member_permissions.serialize is not a function
at /Users/NAME/Desktop/Yara/Commands/Info/help.js:41:78
at /Users/NAME/Desktop/Yara/node_modules/@discordjs/collection/dist/index.js:239:14
at Function.from (<anonymous>)
at Collection.map (/Users/NAME/Desktop/Yara/node_modules/@discordjs/collection/dist/index.js:237:18)
at /Users/NAME/Desktop/Yara/Commands/Info/help.js:35:12
at Array.map (<anonymous>)
at Object.execute (/Users/NAME/Desktop/Yara/Commands/Info/help.js:32:38)
at Object.execute (/Users/NAME/Desktop/Yara/Events/Interactions/interactionCreate.js:42:21)
at Client.<anonymous> (/Users/NAME/Desktop/Yara/Handlers/eventHandler.js:29:67)
at Client.emit (node:events:524:35)
at InteractionCreateAction.handle (/Users/NAME/Desktop/Yara/node_modules/discord.js/src/client/actions/InteractionCreate.js:97:12)
at module.exports [as INTERACTION_CREATE] (/Users/NAME/Desktop/Yara/node_modules/discord.js/src/client/websocket/handlers/INTERACTION_CREATE.js:4:36)
at WebSocketManager.handlePacket (/Users/NAME/Desktop/Yara/node_modules/discord.js/src/client/websocket/WebSocketManager.js:352:31)
at WebSocketShard.onPacket (/Users/NAME/Desktop/Yara/node_modules/discord.js/src/client/websocket/WebSocketShard.js:494:22)
at WebSocketShard.onMessage (/Users/NAME/Desktop/Yara/node_modules/discord.js/src/client/websocket/WebSocketShard.js:328:10)
at callListener (/Users/NAME/Desktop/Yara/node_modules/ws/lib/event-target.js:290:14)

Node.js v19.8.1
this is how i am accessing the info:
{
folder: 'Info',
data: SlashCommandBuilder {
options: [],
name: 'help',
name_localizations: undefined,
description: 'Get a list of all the commands form the discord bot.',
description_localizations: undefined,
default_permission: undefined,
default_member_permissions: undefined //typically set. not set for this command,
dm_permission: undefined,
nsfw: undefined
},
execute: [AsyncFunction: execute]
}
{
folder: 'Info',
data: SlashCommandBuilder {
options: [],
name: 'help',
name_localizations: undefined,
description: 'Get a list of all the commands form the discord bot.',
description_localizations: undefined,
default_permission: undefined,
default_member_permissions: undefined //typically set. not set for this command,
dm_permission: undefined,
nsfw: undefined
},
execute: [AsyncFunction: execute]
}
Decided to remove this feature as it is too complicated and not very useful
Want results from more Discord servers?
Add your server