admin管理员组文章数量:1417054
I want to delete all the messages posted by a particular user. So far I have:
async function clear() {
let botMessages;
botMessages = await message.channel.fetch(708292930925756447);
message.channel.bulkDelete(botMessages).then(() => {
message.channel.send("Cleared bot messages").then(msg => msg.delete({timeout: 3000}))
});
}
clear();
There seems to be an issue with passing botMessages to bulkDelete(), it wants an array or collection but apparantly botMessages isn't an array or collection.
How would I give botMessages to bulkDelete, or am I going about this totally wrong?
I want to delete all the messages posted by a particular user. So far I have:
async function clear() {
let botMessages;
botMessages = await message.channel.fetch(708292930925756447);
message.channel.bulkDelete(botMessages).then(() => {
message.channel.send("Cleared bot messages").then(msg => msg.delete({timeout: 3000}))
});
}
clear();
There seems to be an issue with passing botMessages to bulkDelete(), it wants an array or collection but apparantly botMessages isn't an array or collection.
How would I give botMessages to bulkDelete, or am I going about this totally wrong?
Share Improve this question asked May 9, 2020 at 3:49 JohnJohn 591 silver badge6 bronze badges 1- If an answer solves your question then accept the answer to let others know it worked – Syntle Commented May 9, 2020 at 4:59
1 Answer
Reset to default 5message.channel.fetch()
fetches the channel the message is sent to, not the messages in that channel.
You need to fetch a certain amount of messages and filter it so you're only getting messages sent by your bot then pass them to bulkDelete()
message.channel.messages.fetch({
limit: 100 // Change `100` to however many messages you want to fetch
}).then((messages) => {
const botMessages = [];
messages.filter(m => m.author.id === BOT_ID_HERE).forEach(msg => botMessages.push(msg))
message.channel.bulkDelete(botMessages).then(() => {
message.channel.send("Cleared bot messages").then(msg => msg.delete({
timeout: 3000
}))
});
})
本文标签: javascriptBulk delete messages by user in DiscordjsStack Overflow
版权声明:本文标题:javascript - Bulk delete messages by user in Discord.js - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1745262612a2650425.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论