我的机器人说它没有踢/禁止的权限

时间:2021-02-17 08:48:25

标签: node.js discord.js bots

我正在用 js 制作一个 Discord 机器人。昨天我完成了一些关于机器人禁止命令的工作,它工作正常。今天我醒来,不要修改任何东西,当我再次尝试时,它说它没有权限。什么都没有改变,也没有人改变机器人的权限,它仍然有管理员。错误信息:

(node:2490) UnhandledPromiseRejectionWarning: DiscordAPIError: Missing Permissions
    at RequestHandler.execute (/home/runner/AUN/node_modules/discord.js/src/rest/RequestHandler.js:154:13)
    at processTicksAndRejections (internal/process/task_queues.js:97:5)
    at async RequestHandler.push (/home/runner/AUN/node_modules/discord.js/src/rest/RequestHandler.js:39:14)

我的代码(有点长):

const Discord = require("discord.js");
const dp = require('discord-prefix');
const lang = require('../language_manager');
const settings = require('discord-server-settings');

module.exports = (message, client) => {
  if (!message.member.permissions.has("BAN_MEMBERS")) return message.reply("You do not have the permission to ban users");
  if (!message.guild.me.hasPermission("BAN_MEMBERS")) return message.reply("I do not have permission to ban users");
  let prefix = dp.getPrefix();
  if(dp.getPrefix(message.guild.id)){
    prefix = dp.getPrefix(message.guild.id);
  }
  var langchar = settings.getSetting('lang', message.guild.id)
  const args = message.content.slice(prefix.length).trim().split(' ');
  const command = args.shift().toLowerCase();
    var noerror = true;
  const member = getUserFromMention(args[0]);
  const reason = args[1] || lang.get('ban_no_reason', langchar);
  const embed1 = new Discord.MessageEmbed()
  .setAuthor('AUN', 'https://drive.google.com/uc?export=view&id=129_JKrVi3IJ6spDDciA5Y5sm4pjUF7eI')
  .setTitle(lang.get('ban_title', langchar))
  .setColor('#ed3f2c')
  .setDescription(lang.get('ban_noone_banned', langchar))
  .setTimestamp()
  .setFooter('Ping: ' + client.ws.ping + ' | '+prefix+command);
  const embed = new Discord.MessageEmbed()
  .setTitle(lang.get('ban_you_title', langchar))
  .setAuthor("AUN", "https://drive.google.com/uc?export=view&id=129_JKrVi3IJ6spDDciA5Y5sm4pjUF7eI")
  .setColor(0x00AE86)
  .setDescription(lang.get('ban_you_part1', langchar)+message.guild.name+lang.get('ban_you_part2', langchar)+message.member.name+lang.get('ban_you_part3', langchar)+reason)
  .setFooter("Ping: "+client.ws.ping+" | AUN discord bot")
  .setTimestamp();
  if (!member) {
    embed1.setTitle(lang.get('ban_error', langchar))
      .setDescription(lang.get('ban_no_mention', langchar))
      .setColor('#bd1300');
      noerror = false;
  }
  if(noerror){
        embed1.setDescription(lang.get('ban_banned_part1', langchar)+member.tag+lang.get('ban_banned_part2', langchar));
        member.send(embed);
    }
    message.channel.send(embed1);
  try{
      return message.guild.member(member).ban();
  }catch (e){
      return;
    }
  
  function getUserFromMention(mention) {
    if (!mention) return;

    if (mention.startsWith('<@') && mention.endsWith('>')) {
      mention = mention.slice(2, -1);

      if (mention.startsWith('!')) {
        mention = mention.slice(1);
      }

      return client.users.cache.get(mention);
    }
  }
}

如果你知道发生了什么,请告诉我

1 个答案:

答案 0 :(得分:1)

你应该检查你是否真的可以禁止该会员。

你可以用 GuildMember#manageable