我尝试使用 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 = [];
批量删除需要什么?是消息 ID 还是其他东西?
我不知道我是否这样做是正确的(显然我不是),因为我开始编码时对javascript或任何相关内容的知识为零。
从通道中删除x
消息的最简单方法是提供2 - 100
中的整数作为 <TextChannel>.bulkDelete
方法的参数。
例:
message.channel.bulkDelete(100).then(() => {
message.channel.send("Deleted 100 messages.").then(msg => msg.delete(3000));
});
Discord 批量删除端点需要您要删除的消息数组。请注意,截至昨天,批量删除端点不会删除超过 2 周的消息。
这是一个更新的;
}else if (command === 'purge') {
const amount = parseInt(args[0]);
if (isNaN(amount)) {
return message.reply('that doesn't seem to be a valid number.');
}
if (isNaN(amount)) {
return message.reply('You have enterd a invalid amount. Try ``purge 5``');
} else if (amount < 2 || amount > 100) {
return message.reply('you need to input a number between 2 and 100.');
}
message.channel.bulkDelete(amount);
message.channel.send(amount + ' ' +'messages deleted');
}
});