How can I prevent the messageDelete event from emitting if the bot deletes the message?

I dont want emit the messageDelete when i use message.delete()
14 Replies
Unknown User
Unknown User2y ago
Message Not Public
Sign In & Join Server To View
d.js docs
d.js docs2y ago
It's good practice to make your bots ignore other bots, including itself. This can be done through a single line of code:
if (<message>.author.bot) return;
if (<message>.author.bot) return;
<message> being whatever you defined message as.
monbrey
monbrey2y ago
Thats not what they asked though. The bot might be deleting messages from other people too
AlexInCube
AlexInCubeOP2y ago
I will ask another one, how do I know who deleted the message? I need the event to be triggered if a user deleted the message. And if it was deleted by a bot, then it should not be triggered. It doesn't matter who originally sent the message.
monbrey
monbrey2y ago
You need to check the audit logs. You can do this either from the messageDelete event, or the guildAuditLogEntryCreate event An audit log is not created if a bot deleted a message, or a user deleted their own message
AlexInCube
AlexInCubeOP2y ago
I will try to experiment with guildAuditLogEntryCreate
ncls.
ncls.2y ago
Assuming that you just don't want it to be triggered when the same bot deletes a message, another very trivial idea would be to create a space in your client variable like client.deletedMessages where you store the message IDs when you delete a message in an array and then your messageDelete event handler checks if the message ID of the deleted message is inside that array and if it is, it takes it out and returns and if it's not, it just does what it would usually do.
AlexInCube
AlexInCubeOP2y ago
guildAuditLogEntryCreate is not emitted if message have only embeds and no content...
monbrey
monbrey2y ago
I dont see why it wouldnt be Unless its for one of the reasons I said, bot deleted the message or user deleted their own message
AlexInCube
AlexInCubeOP2y ago
i delete the bot messages in Discord Gui and when i delete the bot message with text like "Hello world" event is triggered but when bot message have only embeds, event is not triggered
monbrey
monbrey2y ago
¯\_(ツ)_/¯ We cant control what the API does
AlexInCube
AlexInCubeOP2y ago
i know I'm tired of using workarounds, but I guess I'll have to think of something else
ncls.
ncls.2y ago
My "workaround" would work without the audit log but it depends on your use case if it's suitable
AlexInCube
AlexInCubeOP2y ago
I used this method after all, the others don't work for me thanks you
Want results from more Discord servers?
Add your server