Reputation: 71
I am making a discord bot (discord.js v14) that has various functions like kicking users, banning users, ...
To ban user users I'm using the following code to register the ban command
const ban = new SlashCommandBuilder().setName('ban').setDescription('Ban member').setDefaultMemberPermissions(PermissionFlagsBits.BanMembers).addUserOption((option) =>
option.setName('user')
.setDescription('The user to ban')
.setRequired(true))
To respond to the registered command, I'm using the following code:
client.on('interactionCreate', (interaction) =>{
if (!interaction.isChatInputCommand) return;
if (interaction.commandName === 'ban'){
try{
interaction.options.getUser('user').ban().then({ embeds:[ new EmbedBuilder().setDescription(`Succesfully banned ${interaction.options.getUser('user')}}`).setColor("#f05c51")
] })
}catch{
interaction.reply({ embeds:[ new EmbedBuilder().setDescription(`Couldn't ban user `).setColor("#f05c51")]})
}
}})
But no matter what I do, it doesn't ban the user
Upvotes: 0
Views: 556
Reputation:
you can't really ban an user, you can ban a member instead, get the member using the user id then ban him
EDIT: or even better instead of using .getUser()
, use .getMember()
, then you can ban him
Upvotes: 1