bulkDelete 如何工作?

新手上路,请多包涵

我尝试使用 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 或任何相关知识的了解为零。

原文由 Neycho Kalaydzhiev 发布,翻译遵循 CC BY-SA 4.0 许可协议

阅读 279
1 个回答

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

例子:

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

原文由 Joseph Goh 发布,翻译遵循 CC BY-SA 3.0 许可协议

撰写回答
你尚未登录,登录后可以
  • 和开发者交流问题的细节
  • 关注并接收问题和回答的更新提醒
  • 参与内容的编辑和改进,让解决方法与时俱进
推荐问题