【问题标题】:Discord.js 'RangeError [BITFIELD_INVALID]: Invalid bitfield flag or number.' [closed]Discord.js 'RangeError [BITFIELD_INVALID]:无效的位域标志或数字。' [关闭]
【发布时间】:2021-12-25 14:03:58
【问题描述】:

我正在尝试创建一个清除命令,但是当我执行它时,它会删除消息,但它会停止机器人并显示错误 RangeError [BITFIELD_INVALID]: Invalid bitfield flag or number.

这是我的 index.js

const Discord = require('discord.js')
const client = new Discord.Client()
const prefix = "%"
const cooldowns = new Discord.Collection();
client.commands = new Discord.Collection();
client.app = app
const fs = require('fs');
const db = require('quick.db')

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.on('message', message => {
  if (!message.content.startsWith(prefix) || message.author.bot) return;

  const args = message.content.slice(prefix.length).trim().split(/ +/);
  const commandName = args.shift().toLowerCase();

  const command = client.commands.get(commandName)
    || client.commands.find(cmd => cmd.aliases && cmd.aliases.includes(commandName));

  if (!command) return;

  if (command.guildOnly && message.channel.type === 'dm') {
    return message.reply('I can\'t execute that command inside DMs!');
  }

  if (command.permissions) {
    const authorPerms = message.channel.permissionsFor(message.author);
    if (!authorPerms || !authorPerms.has(command.permissions)) {
      return message.reply('You can not do this!');
    }
  }

  if (command.args && !args.length) {
    let reply = `You didn't provide any arguments, ${message.author}!`;

    if (command.usage) {
      reply += `\nThe proper usage would be: \`${prefix}${command.name} ${command.usage}\``;
    }

    return message.channel.send(reply);
  }
  if (command.permissions) {
    const authorPerms = message.channel.permissionsFor(message.client.user);
    if (!authorPerms || !authorPerms.has(command.permissions)) {
      return message.channel.reply('You can not do this!');
    }
  }

  if (!cooldowns.has(command.name)) {
    cooldowns.set(command.name, new Discord.Collection());
  }

  const now = Date.now();
  const timestamps = cooldowns.get(command.name);
  const cooldownAmount = (command.cooldown || 3) * 1000;

  if (timestamps.has(message.author.id)) {
    const expirationTime = timestamps.get(message.author.id) + cooldownAmount;

    if (now < expirationTime) {
      const timeLeft = (expirationTime - now) / 1000;
      return message.reply(`please wait ${timeLeft.toFixed(1)} more second(s) before reusing the \`${command.name}\` command.`);
    }
  }

  timestamps.set(message.author.id, now);
  setTimeout(() => timestamps.delete(message.author.id), cooldownAmount);

  try {
    command.execute(message, args);
  } catch (error) {
    console.error(error);
    message.reply('there was an error trying to execute that command!');
  }
});

还有我的 purge.js


module.exports = {
  name: "purge",
  description: "Deletes an amount of messages",
  guildOnly: true,
  permissions: "MANAGE_MESSAGE",
  execute(message, args) {
    if(args[0]){
      if(isNaN(args[0])) return message.reply("That is not a number")
      message.channel.bulkDelete(args[0])
      message.reply(`I. have deleted ${args[0]} messages`)
    } else {
      message.reply("You did not provide a number")
    }
  }
}

当我执行%purge 时,它会删除消息,但完成后它不会回复,它也会退出程序。所以每次使用命令都得重启bot。

【问题讨论】:

  • 打错了,MANAGE_MESSAGE 应该是MANAGE_MESSAGES,复数形式。

标签: javascript node.js discord.js


【解决方案1】:

您的permissions 值中的MANAGE_MESSAGE 权限无效,您必须改用MANAGE_MESSAGES!所有烫发列表都可以找到here

【讨论】:

    猜你喜欢
    • 2020-12-10
    • 2021-08-05
    • 2022-06-13
    • 1970-01-01
    • 1970-01-01
    • 2021-12-12
    • 2021-08-04
    • 2021-01-03
    • 1970-01-01
    相关资源
    最近更新 更多