This issue outlines two enhancements to how events work in guilded.py. The first is the addition of more granular event control: restraining categories of events based on what your client needs. The second is a rework to how parameters are passed to event callbacks.
Granular events
discord.py implements a similar idea with its enable_debug_events parameter for Clients. This enhancement proposes the addition of this parameter as well as a use_discordpy_style_events parameter in order to "switch" event behavior to be more akin to discord.py. This would currently only detail event names (e.g., server_join vs. guild_join - only one or the other), but its effects are greater when considering the following change:
Event parameters
This change is considerably more impactful. If you are familiar with the JavaScript event system (with its Event and inheritors) then this may ring a bell for you. Instead of the following:
async def on_message(message):
# message is a ChatMessage
...
you would handle events like so:
async def on_message(event):
# event is a MessageEvent
message = event.message
# message is a ChatMessage
This change could also come with the decision to drop raw_ events in exchange for a more unified interface:
async def on_message_update(event):
before = event.before # could be None. Such a value indicates that the message was not cached.
after = event.after # always a ChatMessage
# To perform cache-dependent logic, the user will essentially mirror the previous internal behavior:
if before is None:
return
This also flattens relatively convoluted events like raw_message_reaction_add and makes the whole event system function similarly. For example:
async def on_message_reaction_add(event):
message = event.message # could be None, but the user will always have event.message_id
emote = event.emote # Emote
# The user will also have event.channel(_id), event.created_by(_id), and event.server(_id)
Guilded does not provide the rich data in its ChannelMessageReactionCreated/ChannelMessageReactionDeleted payloads that would make Reaction a better model to have here.
This would also enable events to include miscellaneous metadata, like that which is seen in TeamMemberRemoved:
async def on_member_remove(event):
member = event.member # could be None, but the user will always have event.server_id and event.user_id
kicked = event.kicked
banned = event.banned
This removes the need for extraneous member_leave and member_kick events which are not present in the bot API.
Conclusion
The latter part of this issue is currently available for use as an opt-in experiment, more details here. Feel free to discuss either of these in the #development channel (see the support header) or in this issue's comments.
This issue outlines two enhancements to how events work in guilded.py. The first is the addition of more granular event control: restraining categories of events based on what your client needs. The second is a rework to how parameters are passed to event callbacks.
Granular events
discord.py implements a similar idea with its
enable_debug_eventsparameter forClients. This enhancement proposes the addition of this parameter as well as ause_discordpy_style_eventsparameter in order to "switch" event behavior to be more akin to discord.py. This would currently only detail event names (e.g.,server_joinvs.guild_join- only one or the other), but its effects are greater when considering the following change:Event parameters
This change is considerably more impactful. If you are familiar with the JavaScript event system (with its
Eventand inheritors) then this may ring a bell for you. Instead of the following:you would handle events like so:
This change could also come with the decision to drop
raw_events in exchange for a more unified interface:This also flattens relatively convoluted events like
raw_message_reaction_addand makes the whole event system function similarly. For example:Guilded does not provide the rich data in its
ChannelMessageReactionCreated/ChannelMessageReactionDeletedpayloads that would makeReactiona better model to have here.This would also enable events to include miscellaneous metadata, like that which is seen in
TeamMemberRemoved:This removes the need for extraneous
member_leaveandmember_kickevents which are not present in the bot API.Conclusion
The latter part of this issue is currently available for use as an opt-in experiment, more details here. Feel free to discuss either of these in the #development channel (see the support header) or in this issue's comments.