我尝试使用bulkDelete使我的机器人删除其消息,但出现此错误:

(node:5724) UnhandledPromiseRejectionWarning: Unhandled promise rejection (rejection id: 1): Error: Bad Request
(node:5724) DeprecationWarning: Unhandled promise rejections are deprecated. In the future, promise rejections that are not handled will terminate the Node.js process with a non-zero exit code.


这是我的代码:

const Discord = require('discord.js');
const bot = new Discord.Client();
const config = require("./config.json");

bot.on('ready', () =>{
    console.log('I am ready!');
});

//var cleanarr=[];

bot.on("message", message =>{
    if (message.author.bot) return;
var cleanarr=[];
        let command = message.content.split(" ")[0];
command = command.slice(config.prefix.length);

        let args = message.content.split(" ").slice(1);
if (message.content == 'lol'){
    message.channel.sendMessage('LUL');
    cleanarr.unshift(`${message.channel.lastMessageID}`);
    }
if (command == "clean") {
    message.channel.sendMessage('Cleaning...');
    message.channel.bulkDelete(cleanarr);
    var cleanarr = [];


bulkDelete需要什么?是消息ID还是其他?

我不知道我是否做对了(显然我不是),因为我是从对javascript或任何相关知识为零开始进行编码的。

最佳答案

从通道删除x消息的最简单方法是提供2 - 100中的整数作为<TextChannel>.bulkDelete方法的参数。

例:

message.channel.bulkDelete(100).then(() => {
  message.channel.send("Deleted 100 messages.").then(msg => msg.delete(3000));
});

07-25 22:01