Home > Software design >  When I try to kick someone on Discord using bot I get an error
When I try to kick someone on Discord using bot I get an error

Time:01-12

when I try to kick someone using a bot I made it keeps on giving a error. I followed CodeLyons tutorial on ban and kicking. which is his 2020 discord bot playlist. This is the error that keeps coming:

(node:5108) DeprecationWarning: The message event is deprecated. Use messageCreate instead (Use node --trace-deprecation ... to show where the warning was created) /home/ayan/Desktop/DiscordBot/node_modules/discord.js/src/rest/RequestHandler.js:350 throw new DiscordAPIError(data, res.status, request); ^

DiscordAPIError: Missing Permissions at RequestHandler.execute (/home/ayan/Desktop/DiscordBot/node_modules/discord.js/src/rest/RequestHandler.js:350:13) at processTicksAndRejections (node:internal/process/task_queues:96:5) at async RequestHandler.push (/home/ayan/Desktop/DiscordBot/node_modules/discord.js/src/rest/RequestHandler.js:51:14) at async GuildMemberManager.kick (/home/ayan/Desktop/DiscordBot/node_modules/discord.js/src/managers/GuildMemberManager.js:363:5) { method: 'delete', path: '/guilds/927169002294345758/members/895937895456735233', code: 50013, httpStatus: 403, requestData: { json: undefined, files: [] } }

my code:

main.js:

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

const prefix = '!';

const client = new Discord.Client({
  intents: [ Discord.Intents.FLAGS.GUILDS, Discord.Intents.FLAGS.GUILD_MESSAGES ]
});

const fs = require('fs');

client.commands = new Discord.Collection();

const commandFiles = fs.readdirSync('./commands/').filter(file => file.endsWith('.js'));

for (const file of commandFiles) {
    const command = require(`./commands/${file}`);

  client.commands.set(command.name, command);
}


client.once('ready', () => {
    console.log('Chilly is 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') {
        client.commands.get('ping').execute(message, args);
    } else if (command === 'kick') {
        client.commands.get('kick').execute(message, args);
    } else if (command === 'ban') {
        client.commands.get('ban').execute(message, args);
    }
});

client.login('***********************************');

kick.js:

module.exports = {
    name: "kick",
    description: "This command kicks a member!",
    execute(message, args) {
        const member = message.mentions.users.first();
        //if (message.member.roles.cache.has('927171204371079208')) {
            if (member) {
                const memberTarget = message.guild.members.cache.get(member.id);
                memberTarget.kick();
                message.channel.send("User has been kicked");
            } else {
                message.channel.send("You couldn't kick that member");
            }
        //} else {
            //message.channel.send("Sorry you don't have the right permissions to send this message");
        //}
    }
}

extra info: library: discord.js nodejs version: 16.13

CodePudding user response:

Your code seems fine.

The error means that the bot does not have the KICK_MEMBERS permission you can fix this by giving the bot admin or the KICK_MEMBERS permission. It could also mean that the bot can't kick the member because they are the owner and/or higher then the bots role

  •  Tags:  
  • Related