【问题标题】:Why is not bulkDelete working in discord.js?为什么 bulkDelete 不能在 discord.js 中工作?
【发布时间】:2021-03-25 07:00:48
【问题描述】:

我尝试对我的不和谐机器人发出批量删除命令,但它不起作用。

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

if(args[1] == 'bulkdelete') {
  const deleteCount = parseInt(args[2], 10);
  message.channel.bulkDelete(deleteCount || 100)
    .then(() => message.reply('Removing messages'))
    .catch(console.error);
}

当我尝试使用它时,它会返回一个错误。 TypeError: Object.entries(...).filter(...).flatMap is not a function

我做错了什么?

【问题讨论】:

  • 我们需要更多的调试信息,也许错误有更多的信息,比如发生错误的行号和文件。

标签: javascript discord.js bulk-delete


【解决方案1】:

我不知道代码的哪一部分具体导致了错误TypeError: Object.entries(...).filter(...).flatMap is not a function,但鉴于正在发生此错误,我可能知道修复方法。

Object.entries() 返回一个数组,array.filter() 返回一个数组,node.js v11+ 中的数组具有函数属性flatMap()。由于错误告诉您 flatMap() 属性不是数组上的函数,因此您可能使用的是旧版本的 nodeJS。

要解决此问题,您需要更新到节点 11 或更新版本。

相关资源:
Javascript - flatMap method over array - (flatMap is not a function)

【讨论】:

  • 谢谢。我更新了 node.js,它工作得很好。
猜你喜欢
  • 1970-01-01
  • 2014-02-21
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多