I’m having trouble with my Discord bot’s member removal feature. When I run the command “exp kick @username reason here”, nothing happens at all. The bot just completely ignores it like the command doesn’t exist.
bot.on('messageCreate', msg => {
let cmd = msg.content.toLowerCase().split('')[0]
if(cmd == botPrefix + 'remove'){
if(msg.guild.member(msg.author).hasPermission('KICK_MEMBERS'))
return msg.channel.send('You lack the required permissions')
if(!msg.guild.member(bot.user).hasPermission('KICK_MEMBERS'))
return msg.channel.send('Bot permissions are insufficient')
const targetUser = msg.mentions.users.first()
if(!targetUser) return msg.channel.send('Unable to locate specified user!')
const kickReason = msg.content.split(' ').slice(2).join(' ')
if(!kickReason) return msg.channel.send('You must provide a reason!')
if(msg.guild.member(targetUser).kickable) return msg.channel.send('User has elevated permissions')
msg.guild.member(targetUser).kick({reason: kickReason})
return msg.channel.send('Successfully removed user `@'+targetUser.tag+'`')
}
})
Any ideas what might be wrong? I’ve checked the bot permissions and they seem fine.
bruh your permission checks are backwards too lol. if(msg.guild.member(msg.author).hasPermission('KICK_MEMBERS')) return msg.channel.send('You lack the required permissions') will send error message when user DOES have perms. add ! before the condition or it’ll never work properly
Your command prefix check is completely broken. You’re using split('') which splits the message into individual characters, not words. When you do split('')[0] you’re only getting the first character of the message, not the actual command.
Change this line:
let cmd = msg.content.toLowerCase().split('')[0]
To this:
let cmd = msg.content.toLowerCase().split(' ')[0]
See the space inside the split method? This’ll properly separate words instead of characters. Also, your command checks for ‘remove’ but you mentioned using ‘exp kick’ in your description - make sure those match up. The logic errors with the permission checks that others mentioned are also valid issues you’ll need to fix.
There’s another issue nobody mentioned - your kickable check is backwards. The line if(msg.guild.member(targetUser).kickable) return msg.channel.send('User has elevated permissions') returns the error when the user CAN be kicked. You want if(!msg.guild.member(targetUser).kickable) instead. Even after fixing the split and permission issues others mentioned, this backwards check would block every kick attempt. Also, check your discord.js version - some of these methods are deprecated in newer versions, so make sure your syntax matches what you’re running.