Any way to add a sort of "middleware" to all listeners

Is there any way to have something like a middleware or precondition for all events? I want to delay all eventlisteners by a certain number of milliseconds in my Bot so audit logs can catch up. The bot only does logging and nothing else. no commands or anything.
Solution:
didnt even see the 2nd argument for the event
Jump to solution
21 Replies
Oreo ™
Oreo ™9mo ago
as far as i can tell you cant add a precondition to an event listener because that wouldn't make sense however, you could create your own class and extend the base Listener and add your custom logic in there
BigBrainAFK
BigBrainAFKOP9mo ago
yeah thats my backup plan since i hoped sapphire has a way to basically middleware them. might also just be something no one really needs
Oreo ™
Oreo ™9mo ago
its a very niche case i guess also are u sure u have to wait for audit logs?
BigBrainAFK
BigBrainAFKOP9mo ago
i have a few events fail to fetch the related audit log
Oreo ™
Oreo ™9mo ago
because waiting for a set amount of millisecond doesn't seem like its gonna work consistently bc of lag and stuff
BigBrainAFK
BigBrainAFKOP9mo ago
well the complex way would be queueing the events and also having a listener for the audit log creation event and then trying to link up the 2
Oreo ™
Oreo ™9mo ago
or just listen for audit log creation and run a switch statement and emit a custom event for each logging action
BigBrainAFK
BigBrainAFKOP9mo ago
i havent found a good way to link audit log creation to a specifc guild im blind
Solution
BigBrainAFK
BigBrainAFK9mo ago
didnt even see the 2nd argument for the event
Oreo ™
Oreo ™9mo ago
yeah i was gonna say the name is guildAuditLogCreate so i would assume it has a guild object in there
BigBrainAFK
BigBrainAFKOP9mo ago
although i also ran into an issue with the audit log create event where it didnt fire for message delete logs be it cached messages or uncached messages
Oreo ™
Oreo ™9mo ago
yeah audit logs arent created if the message author deleted their own message ur gonna have to make an event listener separately for that
BigBrainAFK
BigBrainAFKOP9mo ago
nono for like a mod deleting it
Oreo ™
Oreo ™9mo ago
oh thats weird ive never messed with audit logs so might be something to do with intents no idea
BigBrainAFK
BigBrainAFKOP9mo ago
yeah thats my best guess but i also receive the normal message delete for any cache message
Oreo ™
Oreo ™9mo ago
u dont really need an audit log case for message delete tho the only thing ur getting is the person who deleted it
BigBrainAFK
BigBrainAFKOP9mo ago
thats what i want link who deleted what so we can just in case question the relevant mod about it
Oreo ™
Oreo ™9mo ago
so is this like random or are the events dropped consistently
BigBrainAFK
BigBrainAFKOP9mo ago
so in guildAuditLogEntryCreate i get no events for message delete at all but the messageDelete event itself works i dont know if this might also be an issue with multiple message deletes from the same executor and target getting condensed into the same log entry just counting up how many messages were removed
Oreo ™
Oreo ™9mo ago
u might have better luck asking in https://discord.com/invite/djs for issues like this, since we have strayed far away from sapphire already
BigBrainAFK
BigBrainAFKOP9mo ago
okay thank you anyway.
Want results from more Discord servers?
Add your server