commands isnt work

TypeError: Cannot read properties of undefined (reading 'FLAGS')
at Object.execute (c:\Users\artem\Desktop\bot\commands\ban\ban.js:16:57)
at Client.<anonymous> (c:\Users\artem\Desktop\bot\index.js:40:17)
at Client.emit (node:events:519:28)
at InteractionCreateAction.handle (c:\Users\artem\Desktop\bot\node_modules\discord.js\src\client\actions\InteractionCreate.js:97:12)
at module.exports [as INTERACTION_CREATE] (c:\Users\artem\Desktop\bot\node_modules\discord.js\src\client\websocket\handlers\INTERACTION_CREATE.js:4:36)
at WebSocketManager.handlePacket (c:\Users\artem\Desktop\bot\node_modules\discord.js\src\client\websocket\WebSocketManager.js:355:31)
at WebSocketManager.<anonymous> (c:\Users\artem\Desktop\bot\node_modules\discord.js\src\client\websocket\WebSocketManager.js:239:12)
at WebSocketManager.emit (c:\Users\artem\Desktop\bot\node_modules\@vladfrangu\async_event_emitter\dist\index.cjs:282:31)
at WebSocketShard.<anonymous> (c:\Users\artem\Desktop\bot\node_modules\@discordjs\ws\dist\index.js:1190:51)
at WebSocketShard.emit (c:\Users\artem\Desktop\bot\node_modules\@vladfrangu\async_event_emitter\dist\index.cjs:282:31)
TypeError: Cannot read properties of undefined (reading 'FLAGS')
at Object.execute (c:\Users\artem\Desktop\bot\commands\ban\ban.js:16:57)
at Client.<anonymous> (c:\Users\artem\Desktop\bot\index.js:40:17)
at Client.emit (node:events:519:28)
at InteractionCreateAction.handle (c:\Users\artem\Desktop\bot\node_modules\discord.js\src\client\actions\InteractionCreate.js:97:12)
at module.exports [as INTERACTION_CREATE] (c:\Users\artem\Desktop\bot\node_modules\discord.js\src\client\websocket\handlers\INTERACTION_CREATE.js:4:36)
at WebSocketManager.handlePacket (c:\Users\artem\Desktop\bot\node_modules\discord.js\src\client\websocket\WebSocketManager.js:355:31)
at WebSocketManager.<anonymous> (c:\Users\artem\Desktop\bot\node_modules\discord.js\src\client\websocket\WebSocketManager.js:239:12)
at WebSocketManager.emit (c:\Users\artem\Desktop\bot\node_modules\@vladfrangu\async_event_emitter\dist\index.cjs:282:31)
at WebSocketShard.<anonymous> (c:\Users\artem\Desktop\bot\node_modules\@discordjs\ws\dist\index.js:1190:51)
at WebSocketShard.emit (c:\Users\artem\Desktop\bot\node_modules\@vladfrangu\async_event_emitter\dist\index.cjs:282:31)
its error
17 Replies
d.js toolkit
d.js toolkit7mo 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!
vekizxo
vekizxoOP7mo ago
const { SlashCommandBuilder } = require('@discordjs/builders');
const { Permissions } = require('discord.js');

module.exports = {
data: new SlashCommandBuilder()
.setName('giverole')
.setDescription('Выдает временную роль пользователю')
.addUserOption(option => option.setName('user').setDescription('Пользователь, которому будет выдана роль').setRequired(true))
.addRoleOption(option => option.setName('role').setDescription('Роль, которая будет выдана пользователю').setRequired(true))
.addIntegerOption(option => option.setName('duration').setDescription('Длительность роли в минутах (0 - навсегда)').setRequired(true)),
async execute(interaction) {
const user = interaction.options.getUser('user');
const role = interaction.options.getRole('role');
const duration = interaction.options.getInteger('duration');

if (!interaction.member.permissions.has(Permissions.FLAGS.MANAGE_ROLES)) {
return interaction.reply({ content: 'У вас недостаточно прав для выдачи ролей.', ephemeral: true });
}

if (role.position >= interaction.member.roles.highest.position) {
return interaction.reply({ content: 'Вы не можете выдать роль, которая находится выше вашей.', ephemeral: true });
}

const member = await interaction.guild.members.fetch(user.id);

if (duration === 0) {
await member.roles.add(role);
return interaction.reply(`{ content: Роль ${role.name} выдана пользователю ${user.username} навсегда., ephemeral: true }`);
} else {
await member.roles.add(role);
setTimeout(() => {
member.roles.remove(role);
}, duration * 60 * 1000);
return interaction.reply(`{ content: Роль ${role.name} выдана пользователю ${user.username} на ${duration} минут., ephemeral: true }`);
}
},
};
const { SlashCommandBuilder } = require('@discordjs/builders');
const { Permissions } = require('discord.js');

module.exports = {
data: new SlashCommandBuilder()
.setName('giverole')
.setDescription('Выдает временную роль пользователю')
.addUserOption(option => option.setName('user').setDescription('Пользователь, которому будет выдана роль').setRequired(true))
.addRoleOption(option => option.setName('role').setDescription('Роль, которая будет выдана пользователю').setRequired(true))
.addIntegerOption(option => option.setName('duration').setDescription('Длительность роли в минутах (0 - навсегда)').setRequired(true)),
async execute(interaction) {
const user = interaction.options.getUser('user');
const role = interaction.options.getRole('role');
const duration = interaction.options.getInteger('duration');

if (!interaction.member.permissions.has(Permissions.FLAGS.MANAGE_ROLES)) {
return interaction.reply({ content: 'У вас недостаточно прав для выдачи ролей.', ephemeral: true });
}

if (role.position >= interaction.member.roles.highest.position) {
return interaction.reply({ content: 'Вы не можете выдать роль, которая находится выше вашей.', ephemeral: true });
}

const member = await interaction.guild.members.fetch(user.id);

if (duration === 0) {
await member.roles.add(role);
return interaction.reply(`{ content: Роль ${role.name} выдана пользователю ${user.username} навсегда., ephemeral: true }`);
} else {
await member.roles.add(role);
setTimeout(() => {
member.roles.remove(role);
}, duration * 60 * 1000);
return interaction.reply(`{ content: Роль ${role.name} выдана пользователю ${user.username} на ${duration} минут., ephemeral: true }`);
}
},
};
command code
d.js docs
d.js docs7mo ago
RangeError [BitFieldInvalid]: Invalid bitfield flag or number: undefined - All SCREAMING_SNAKE_CASE enums have been changed to PascalCase - Intents: Intents.FLAGS.GUILD_MESSAGES -> GatewayIntentBits.GuildMessages - Permissions: Permissions.FLAGS.SEND_MESSAGES -> PermissionFlagsBits.SendMessages
Unknown User
Unknown User7mo ago
Message Not Public
Sign In & Join Server To View
vekizxo
vekizxoOP7mo ago
I don't really understand what exactly I need to do
Unknown User
Unknown User7mo ago
Message Not Public
Sign In & Join Server To View
vekizxo
vekizxoOP7mo ago
I read it but didn't understand it
Unknown User
Unknown User7mo ago
Message Not Public
Sign In & Join Server To View
vekizxo
vekizxoOP7mo ago
what should i change
Unknown User
Unknown User7mo ago
Message Not Public
Sign In & Join Server To View
vekizxo
vekizxoOP7mo ago
how is it similar to v13
Unknown User
Unknown User7mo ago
Message Not Public
Sign In & Join Server To View
vekizxo
vekizxoOP7mo ago
if (!interaction.member.permissions.has(PermissionFlagsBits.MANAGE_ROLES)) {
if (!interaction.member.permissions.has(PermissionFlagsBits.MANAGE_ROLES)) {
right?
Unknown User
Unknown User7mo ago
Message Not Public
Sign In & Join Server To View
vekizxo
vekizxoOP7mo ago
if (!interaction.member.permissions.has(PermissionFlagsBits.ManageRoles)) {
if (!interaction.member.permissions.has(PermissionFlagsBits.ManageRoles)) {
No description
Unknown User
Unknown User7mo ago
Message Not Public
Sign In & Join Server To View
vekizxo
vekizxoOP7mo ago
all work. one more question, how can I make it so that instead of indicating minutes I could indicate 1d 2d 1m 1s thx
Want results from more Discord servers?
Add your server