Delete bot Message in a DM Channel !

Hey ! I'd know if it's possible to clear all messages from the bot in a DM channel ! I tried in many way, but nothing succeed ! Does anyone have any leads and more importantly, are these messages really deletable? Thanks !
5 Replies
d.js docs
d.js docs2y ago
• What's your exact discord.js npm list discord.js and node node -v version? • Post the full error stack trace, not just the top part! • Show your code! • Explain what exactly your issue is. • Not a discord.js issue? Check out #useful-servers.
chewie 🌈
chewie 🌈2y ago
you would have to fetch all the messages in the channel, filter the ones not from your bot out, iterate over them and call .delete() on each of them. aka not recommended why do you even need this
Akihiro
Akihiro2y ago
I tried with that :
const channel = client.channels.cache.get(/*myDMChannelIDWithTheBot*/);
const messages = await channel.messages.fetch({ limit: 10 });
const messageToDel = messages.filter((mess) => {
return mess.author.id === /*BotID*/;
})

for (const mess of messageToDel) {
console.log(mess.content);
}
const channel = client.channels.cache.get(/*myDMChannelIDWithTheBot*/);
const messages = await channel.messages.fetch({ limit: 10 });
const messageToDel = messages.filter((mess) => {
return mess.author.id === /*BotID*/;
})

for (const mess of messageToDel) {
console.log(mess.content);
}
But all console log return undefined... in fact, no matter which property I try to access, it returns "undefined". But if I log the whole object, I can see the properties and their values, is it an Intents problem ? To clear the DMs I have with my bot which is getting messy with all my tests x)
chewie 🌈
chewie 🌈2y ago
const mess of [...messageToDel.values()]
Akihiro
Akihiro2y ago
Owh ! Yeah ! It worked ! I guess I have to review my knoweldge on Maps x) Thanks ! = )