Ban to bot command on Discord.js

Asked

Viewed 7,958 times

-1

I’m trying to make a ban command for my Discord.js bot, but he says I don’t have permission, even though I’m one of the server administrators (even the guy with Ownership can’t do it).

if(comando === "ban") {
    if(!message.member.roles.some(r=>["Administrator"].includes(r.name)) )
      return message.reply("Você não tem permissões para usar este comando.");
    let member = message.mentions.members.first();
    if(!member)
      return message.reply("Por favor, mencione um usuário válido.");
    if(!member.bannable) 
      return message.reply("Eu não posso banir este usuário! Ele pode ter um 
      cargo maior que o meu, ou eu não tenha permissão pra banir!");
    let reason = args.slice(1).join(' ');
    if(!reason) reason = "Forneça uma razão à esse banimento.";
    await member.ban(reason)
      .catch(error => message.reply("Desculpe ${message.author} não consegui banir o membro devido ao : ${error}"));
    message.reply("${member.user.tag} foi banido por ${message.author.tag} pelo motivo de: ${reason}`);
  }
  • But the [Administrator] is already marked in this code: if(!message.member.roles.some(r=>["Administrator"].includes(r.name)) ), where should I put it, then?

  • My Discord is in English, and it says "Administrator" on the roles part.

  • Try creating a new role with a different name to test and see the result. Here, the same code works perfectly.

  • I did that, I created a role called Administrator, and it worked. But I wanted to know if it is possible to schedule so that all the positions that had the admin permission could run the ban.

3 answers

0

In your code, the bot is checking if the person has a role with the exact name "Administrator", so probably your role should be under another name.

You can put pro bot check if the person has the Administrator permission with if(!message.member.hasPermission('ADMINISTRATOR')) return message.reply('Sem permissão')

Or with the permission "BAN MEMBERS" if(!message.member.hasPermission('BAN_MEMBERS')) return message.reply('Sem permissão')

You should just change the string of hasPermission()

0

Apparently, the error is in the user’s role. The group name should be exactly as in the code ["Administrator"]

It is possible that in your Discord the role is as "Manageaching" and this is causing the lack of permission.

-1

Whoever the member has admin permissions to execute the command is this command here:

    if(!message.member.hasPermission('ADMINISTRATOR'))
    return message.reply("Você não tem permissões para usar este comando.");

Example in the imageinserir a descrição da imagem aqui

Browser other questions tagged

You are not signed in. Login or sign up in order to post.