我尝试使用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或任何相关的知识进行编码。
答案 0 :(得分:2)
从频道中删除x
消息的最简单方法是提供2 - 100
的整数作为<TextChannel>.bulkDelete
方法的参数。
示例:
message.channel.bulkDelete(100).then(() => {
message.channel.send("Deleted 100 messages.").then(msg => msg.delete(3000));
});
答案 1 :(得分:1)
discord批量删除端点需要您要删除的邮件数组。截至昨天的小注释,批量删除端点不会删除超过2周的邮件。
答案 2 :(得分:0)
这里更新了一点;
}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');
}
});