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.
21 Replies
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
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
its a very niche case i guess
also are u sure u have to wait for audit logs?
i have a few events fail to fetch the related audit log
because waiting for a set amount of millisecond doesn't seem like its gonna work consistently
bc of lag and stuff
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
or just listen for audit log creation
and run a switch statement
and emit a custom event for each logging action
i havent found a good way to link audit log creation to a specifc guild
im blind
Solution
didnt even see the 2nd argument for the event
yeah i was gonna say
the name is guildAuditLogCreate so i would assume it has a guild object in there
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
yeah audit logs arent created if the message author deleted their own message
ur gonna have to make an event listener separately for that
nono for like a mod deleting it
oh thats weird
ive never messed with audit logs
so might be something to do with intents
no idea
yeah thats my best guess but i also receive the normal message delete for any cache message
u dont really need an audit log case for message delete tho
the only thing ur getting is the person who deleted it
thats what i want
link who deleted what so we can just in case question the relevant mod about it
so is this like random or are the events dropped consistently
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
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
okay thank you anyway.