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•2y ago
Message Not Public
Sign In & Join Server To View
It's good practice to make your bots ignore other bots, including itself. This can be done through a single line of code:
<message> being whatever you defined message as.
Thats not what they asked though. The bot might be deleting messages from other people too
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.
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
I will try to experiment with guildAuditLogEntryCreate
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.guildAuditLogEntryCreate is not emitted if message have only embeds and no content...
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
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
¯\_(ツ)_/¯
We cant control what the API does
i know
I'm tired of using workarounds, but I guess I'll have to think of something else
My "workaround" would work without the audit log but it depends on your use case if it's suitable
I used this method after all, the others don't work for me
thanks you