本文介紹了批量刪除如何工作?的處理方法,對大家解決問題具有一定的參考價值,需要的朋友們下面隨著小編來一起學習吧!
問題描述
我嘗試使用 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));
});
這篇關于批量刪除如何工作?的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網!
【網站聲明】本站部分內容來源于互聯網,旨在幫助大家更快的解決問題,如果有圖片或者內容侵犯了您的權益,請聯系我們刪除處理,感謝您的支持!