#pls help fix error
6 messages · Page 1 of 1 (latest)
send the code and errors and not images!
TypeError: Cannot read properties of undefined (reading 'permissions')
at Object.execute (D:\discordmdr\moderator\ban.js:31:49)
at Client.<anonymous> (D:\discordmdr\index.js:76:19)
at Client.emit (node:events:519:28)
at InteractionCreateAction.handle (D:\discordmdr\node_modules\discord.js\src\client\actions\InteractionCreate.js:97:12)
at module.exports [as INTERACTION_CREATE] (D:\discordmdr\node_modules\discord.js\src\client\websocket\handlers\INTERACTION_CREATE.js:4:36)
at WebSocketManager.handlePacket (D:\discordmdr\node_modules\discord.js\src\client\websocket\WebSocketManager.js:355:31)
at WebSocketManager.<anonymous> (D:\discordmdr\node_modules\discord.js\src\client\websocket\WebSocketManager.js:239:12)
at WebSocketManager.emit (D:\discordmdr\node_modules@vladfrangu\async_event_emitter\dist\index.cjs:282:31)
at WebSocketShard.<anonymous> (D:\discordmdr\node_modules@discordjs\ws\dist\index.js:1173:51)
at WebSocketShard.emit (D:\discordmdr\node_modules@vladfrangu\async_event_emitter\dist\index.cjs:282:31)
I can't code, restrictions
async execute(interaction) {
const targetUser = interaction.options.getUser('target');
const reason = interaction.options.getString('reason') || 'No reason provided';
const time = interaction.options.getString('time');
// Проверка на наличие необходимых разрешений у бота
const botPermissions = interaction.guild.me.permissions;
if (!interaction.guild.me || !interaction.guild.me.permissions) {
return interaction.reply({ content: 'Unable to fetch bot permissions. Please make sure the bot has the necessary permissions.', ephemeral: true });
}
// Дополнительная логика обработки времени, если оно предоставлено
try {
if (time) {
const duration = parseTime(time);
await interaction.guild.members.ban(targetUser, { reason, days: duration.days });
} else {
await interaction.guild.members.ban(targetUser, { reason });
}
await interaction.reply({ content: `Successfully banned ${targetUser.tag} with reason: ${reason}`, ephemeral: true });
} catch (error) {
console.error(error);
await interaction.reply({ content: 'There was an error while executing this command!', ephemeral: true });
}
},
};