简体   繁体   English

为什么 bulkDelete 在 discord.js 中不起作用?

[英]Why is not bulkDelete working in discord.js?

I tried to make a bulk delete command to my discord bot, but it doesn't work.我试图对我的 discord 机器人发出批量删除命令,但它不起作用。

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);
}

When I try to use it, it returns an error.当我尝试使用它时,它会返回一个错误。 TypeError: Object.entries(...).filter(...).flatMap is not a function

What am I doing wrong?我究竟做错了什么?

I don't know what part of the code is specifically causing the error TypeError: Object.entries(...).filter(...).flatMap is not a function , but given that this error is occurring, I may know a fix.我不知道代码的哪一部分具体导致了错误TypeError: Object.entries(...).filter(...).flatMap is not a function ,但鉴于此错误正在发生,我可能知道一个修复。

Object.entries() returns an array, array.filter() returns an array, and arrays in node.js v11+ have the function property flatMap() . Object.entries() returns an array, array.filter() returns an array, and arrays in node.js v11+ have the function property flatMap() . Since the error is telling you that the flatMap() property is not a function on an array, you're probably using an older version of nodeJS.由于错误告诉您flatMap()属性不是数组上的 function,因此您可能使用的是较旧版本的 nodeJS。

To fix this, you need to update to node 11 or a newer version.要解决此问题,您需要更新到节点 11 或更新版本。

Relevant resources:相关资源:
Javascript - flatMap method over array - (flatMap is not a function) Javascript - 数组上的 flatMap 方法 - (flatMap 不是函数)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM