本文介绍了bulkDelete如何工作?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我尝试使用bulkDelete
使我的机器人删除其消息,但出现此错误:
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.
这是我的代码:
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还是其他?
What does the bulkDelete need? Is it the message id or something else?
我不知道我是否做对了(显然我没有这样做),因为我是从对javascript或任何相关知识为零开始编码的.
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.
推荐答案
从通道删除x
消息的最简单方法是提供2 - 100
中的整数作为 <TextChannel>.bulkDelete
方法.
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.
示例:
message.channel.bulkDelete(100).then(() => {
message.channel.send("Deleted 100 messages.").then(msg => msg.delete(3000));
});
这篇关于bulkDelete如何工作?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!