Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

148
Visualizações
My discord test bot returns 'You do not have the permission to use that command' even though I clearly have it on the channel for my role

I'm watching a youtube tutorial to try and make a bot for my discord server I think I'm having a problem with 'KICK_MEMBERS' because even though I have that permission, it returns 'You do not have permission to use that command'. Earlier, the error was that (hasPermission) is not a function. I'm mentioning this because maybe the tutorial video was just outdated. I'm not sure since it is returning the 'You do not have permission to use that command'. Maybe I'm missing something. What to do?

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
1 Respostas
Responde à pergunta

0

Your bot says You don't permission to use this command because you use:

if (message.member.permissions.has('KICK_MEMBERS')) 
return message.reply('You do not have permission to use that command');

Which will only return if you HAVE this permission so you have to add ! before message.member.permissions.has, like this:

if (!message.member.permissions.has('KICK_MEMBERS')) 
return message.reply('You do not have permission to use that command');
about 4 years ago · Juan Pablo Isaza Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda