Reputation: 43
My code:
const Discord = require("discord.js");
module.exports.run = async (bot, message, args) => {
const amount = args[0]
if (!amount) return message.reply('Must specify an amount to delete!');
message.channel.fetchMessages({
limit: amount,
}).then((messages) => {
message.delete(messages).catch(error => console.log(error.stack));
});
message.delete().catch(O_o => { });
}
module.exports.help = {
name: "clear"
}
Problem: I'm running the bot on my account and trying to make it delete messages on a command execution. Errors: DiscordAPIError: Unknown Message at item.request.gen.end (C:\Users\brian\node_modules\discord.js\src\client\rest\RequestHandlers\Sequential.js:79:15) at then (C:\Users\brian\node_modules\snekfetch\src\index.js:215:21) at process._tickCallback (internal/process/next_tick.js:68:7)
Upvotes: 1
Views: 466
Reputation: 6015
The problem is that message.delete
expects a number for timeout and not the array of messages
You might want to do something like
.then((messages) => {
Promise.all(messages.map(msg => msg.delete()))
.then(() => message.delete()) //delete original message after others are cleared
.catch(error => console.log(error.stack));
});
Upvotes: 2