user13718156
user13718156

Reputation:

discord.js ban/kick commands

basically all i need are simple commands that lets me type

<ban [user here] or <kick [user here]

and have have it kick/ban the refrenced user, i know this is probably the simplest thing in the world but i suck and im really new to discord bot coding and js in general so help me random people :D also this is probobly the stupidest thing in the world but i found another thing on this and it didnt work heres the code they tried:

if (msg.member.hasPermission("KICK_MEMBERS") {
    if (msg.members.mentions.first()) {
        try {
            msg.members.mentions.first().kick();
        } catch {
            msg.reply("I do not have permissions to kick " + msg.members.mentions.first());
    }else {
        msg.reply("You do not have permissions to kick " + msg.members.mentions.first());
}

here is my code so far:

  const Discord = require('discord.js');

  const client = new Discord.Client();

  const prefix = '<';

  client.once('ready', () => {
console.log('Bot Online')
client.channels.cache.get('707840645192220714').send('Bot Online');
})

client.on('message', message => {
    if (!message.content.startsWith(prefix) || message.author.bot) return;

const args = message.content.slice(prefix.length).split(/ +/);
const command = args.shift().toLowerCase();

if (command === 'ping>') {
    message.channel.send('pong!');
}
else if (command === 'test>') {
    message.channel.send('Test Working');
}
else if (command === 'help>') {
    message.channel.send('<Ping> <Test> <Help> <Youtube>')
}
else if (command === 'youtube>'){
    message.channel.send('https://www.youtube.com/channel/UCFK-ry9dVqsPsjr638g1ygw')
}
else if (command === 'kick>'){
         
    }

else (message.channel.send('That Command Isnt Reconised Use <Help> To View 
   A List Of Commands'))
   })

   client.login('Token Here');

also im not going to require it but if you want you could help me get the suffix system working without having to just shove it at the end of my commands

Upvotes: 0

Views: 751

Answers (1)

Chiitoi
Chiitoi

Reputation: 71

For the code you tried, it doesn't work as there is no members property on the Message object. I think what you want to try is msg.mentions.members.first() - this gives you the first valid mention as a GuildMember object. From here, you can use the kick() and ban() methods as you please.

Upvotes: 1

Related Questions