How does bulkDelete work?

佐手、 提交于 2020-06-28 04:12:23

问题


I tried using bulkDelete to make my bot delete its message but I get this error:

(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.

And here is my 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 = [];

What does the bulkDelete need? Is it the message id or something else?

I have no idea if I doing this right (obviously I am not) since I started coding with zero knowledge of javascript or anything related.


回答1:


The easiest way to delete x messages from a channel is to provide an integer from 2 - 100 as parameters to the <TextChannel>.bulkDelete method.

Example:

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



回答2:


The discord bulk delete endpoint requires the array of messages you would like deleted. Small note here as of yesterday the bulk delete endpoint will not remove messages older than 2 weeks.



来源:https://stackoverflow.com/questions/41574971/how-does-bulkdelete-work

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!