Reputation: 23
I'm writing a bot which logs user reactions to specific messages (events). Each generates a message containing id of the event to which they reacted on a log channel. Now I'm trying to get the bot to remove any generated messages for an event if the reaction was removed. My code:
client.on("messageReactionRemove", (reaction, user) => {
if(user.bot) return;
let message = reaction.message;
ORid = message.id;
ORid = ORid.toString();
if(message.channel.id == '709887163084439555') {
if(message.content.charAt(0) == '|'){
var logChannel = client.channels.get('710092733254991893')
logChannel.fetchMessages().then(messages => {
var msgToRemove = messages.filter(m => message.content.includes(ORid))
logChannel.bulkDelete(msgToRemove)
}).catch(err => {
console.log('Error while doing Bulk Delete');
console.log(err);
});
} else return;
} else return;
});
The first id is event channel, the other is where logs are generated. However, instead of filtering all the messages on the log channel, it checks whether the event contains it's id and if so, purges all logs. What can I do to fix this?
Upvotes: 2
Views: 978
Reputation: 66
It looks like you have a bug in the line filtering the messages:
var msgToRemove = messages.filter(m => message.content.includes(ORid))
You're checking message.content.includes(ORid)
, which is always going to be false
.
This is because you're using the message
variable defined earlier instead of m
from the filter. The correct way to write the line would be:
var msgToRemove = messages.filter(m => m.content.includes(ORid))
Upvotes: 1