Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

147
Views
My Discord test bot returns 'That member was not found' even though the member is in my server

I'm watching a video tutorial on YouTube on how to make a Discord bot. I believe I kinda understand what I'm doing at this point. But I just have no idea why it returns that. I did as the video said and everything was working until that point where I was testing kicking members from the server.

Here is my code:

require('dotenv').config();

const {Client} = require('discord.js');
const client = new Client({ intents: ["GUILDS", "GUILD_MESSAGES"] });
const PREFIX = "y!";


client.on('ready', () => {
    console.log(`${client.user.tag} has logged in.`);
});

client.on('messageCreate', (message) => {
    if (message.author.bot) return;
    console.log(`[${message.author.tag}]: ${message.content}`);
    if (message.content === 'hello') {
        message.reply('konnichiwa');
        message.channel.send('mata konnichiwa');
        message.channel.send('konnichiwa');
    }
    if (message.content.startsWith(PREFIX)) {
        const [CMD_NAME, ...args] = message.content
            .trim()
            .substring(PREFIX.length)
            .split(/\s+/);
        console.log(CMD_NAME);
        console.log(args); 

        if (CMD_NAME === 'kick') {
            if (!message.member.permissions.has('KICK_MEMBERS')) 
                return message.reply('You do not have permission to use that command');
            if (args.length === 0) 
                return message.reply('Please provide an ID.');
            const member = message.guild.members.cache.get(args[0]);
            if (member) {
                member.kick().then((member) => message.channel.send(`${member} was kicked`)).catch((err) => message.channel.send('I do not have permissions...'));
            }   else {
                message.channel.send('That member was not found...');
            }

            
        }
        else if (CMD_NAME === 'ban') {
            if (!message.member.permissions.has('BAN_MEMBERS'))
                return message.reply('You do not have permission to use that command');
            if (args.length === 0) return message.reply('Please provide an ID.');
            message.guild.members.ban(args[0]);
        }
    }
})

client.login(process.env.DISCORDJS_BOT_TOKEN);
about 4 years ago · Juan Pablo Isaza
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!