When I want to clear messages with the code below:
await message.channel.messages.fetch({limit: args[0]}).then(messages =>{
message.channel.send(`Deleting Messages...`).then(msg => {
setTimeout(() => msg.delete(), 500)
})
message.channel.bulkDelete(messages);
});
It works, But when I say: "${prefix}clear 3", It deletes 2 messages. or when the messages are for more than the last 14 days, it cannot delete the messages.
List:
Extra Note: I am using discord.js v13 and node.js v16
message.delete()
Channel.bulkDelete()
is not removing messages that are older than 2 weeks by default! To enable filterOld
parameter you'll have to use Channel.bulkDelete(number, true)
and you'll be able to delete these messages as well!First of all, your command is a message thats why it deletes less that the amount Second of all, bots cannot delete messages that are older than 2 weeks third of all, you cannot delete more than 100 messages. so you can do:
const amount = args[0]
if (amount > 100 || amount < 1) {
return message.channel.send({content: `I cannot delete 100 messages or more`})
}
const messages = await message.channel.messages.fetch({
limit: amount + 1,
});
await message.channel.bulkDelete(messages, true)
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.