'How do I delete all messages in a discord channel with js?
Using discord.py in python, I can do the following and it'll slowly delete all messages in a channel even if they're more than 2 weeks old:
async def clear(self, ctx):
length = await ctx.message.channel.history(limit=999).flatten()
num = len(length)
div = 100
target = [num // div(1 if x < num % div else 0) for x in range(div)]
for tar in target:
async for message in ctx.message.channel.history(limit=tar):
await ctx.message.channel.delete_messages([message])
How would I go about doing the same thing in javascript discord.js?
Solution 1:[1]
This is the common function for it, however bulkDelete does have 2 week limitation and 100 message limit.
async function clearChat (msg, numb) {
const channel = msg.channel;
const messageManager = channel.messages;
const messages = await messageManager.channel.messages.fetch({ limit: numb });
channel.bulkDelete(messages,true);
}
To call it just:
clearChat(msg, 100);
In your code
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | 19mike95 |
