const Command = require('../../ Structures / Command'); const Discord = require('discord.js');
module.exports = class extends Command {
constructor(...args) {
super(...args, {
aliases: ['clear']
});
}
async run(message, args) {
// This command removes all messages from all users in the channel, up to 100.
if(!message.member.hasPermission("KICK_MEMBERS"))
return message.reply("Sorry, you don't have permissions to use this!");
// get the delete count, as an actual number.
const deleteCount = parseInt(args[0], 10);
// Ooooh nice, combined conditions. <3
if(!deleteCount || deleteCount < 1 || deleteCount > 100)
return message.reply("Please provide a number between 1 and 100 for the number of messages to delete");
// So we get our messages, and delete them. Simple enough, right?
const fetched = await message.channel.messages.fetch({limit: deleteCount});
message.channel.send(fetched.size + ` deleted messages by ${message.author.tag}`).then(msg => {msg.delete(2000)});
message.channel.bulkDelete(fetched)
}
};
这很好用,但是有一个错误提示:
(node:1132) UnhandledPromiseRejectionWarning: TypeError [INVALID_TYPE]: Supplied options is not an object.
at Message.delete (C:\Users\xdswe\Desktop\Zero\node_modules\discord.js\src\structures\Message.js:501:44)
at C:\Users\xdswe\Desktop\Zero\src\commands\Utilities\Purge.js:26:118
at processTicksAndRejections (internal/process/task_queues.js:97:5)
(node:1132) UnhandledPromiseRejectionWarning: Unhandled promise rejection. This error originated either by throwing inside of an async function without a catch block,
or by rejecting a promise which was not handled with .catch(). To terminate the node process on unhandled promise rejection, use the CLI flag `--unhandled-rejections=s
trict` (see https://nodejs.org/api/cli.html#cli_unhandled_rejections_mode). (rejection id: 2)
请帮助
答案 0 :(得分:0)
这是由代码的最后一部分引起的,因为discord.js v12 Message.delete()
需要一个带有选项timeout
和reason
的对象,这些选项是可选的,但是在您的情况下, timeout
像这样2000
:
// So we get our messages, and delete them. Simple enough, right?
const fetched = await message.channel.messages.fetch({limit: deleteCount});
message.channel.send(fetched.size + ` deleted messages by ${message.author.tag}`)
.then(msg => {msg.delete({ timeout: 2000 })});
message.channel.bulkDelete(fetched)