-
Notifications
You must be signed in to change notification settings - Fork 139
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat(interactions): deserialize channel
from data
#1012
Conversation
958443b
to
fd14756
Compare
fd14756
to
be8b678
Compare
I really don't like this assumption, and would like some fallback to current behavior in the event that the channel data is not present (it was already rolled back once for breaking d.js). |
Looks like the assumption that I can't reproduce it, but I was afraid this might happen. It makes this field a lot more annoying to work with; not sure how to handle this properly right now, I don't want to just slap a try/except around it. edit: looked into it further, the linked issue may be slightly inaccurate and we actually do get this data here |
I don't think there are even cases where `resolved["messages"]` can contain a message that *isn't* in the current channel, so `channel_id == parent.channel.id` should always match. Still, we fall back to `guild.get_channel()` in case it doesn't. Additionally, we also fall back in the same way to `state.get_channel()` to make use of the DM cache if `parent.channel` is a `PartialMessageable`, since that means it's a dm/group channel, for which support will be added in another PR.
Summary
Implements discord/discord-api-docs@88a7618, deserializing the
channel
field from the interaction payload and no longer using thechannel_id
field.This has no effect for channels which are already cached, but it now provides a proper channel object in cases where it isn't (no bot in guild, private threads, ...).
A few comments on safety
The continued assumption is that all non-PING interactions contain this
channel
field, which is what we're already assuming forchannel_id
. However, this is not documented.Making the
channel
field optional in the future is definitely worth consideration, imo, but for now it might be too much of a breaking change in terms of typing.Similarly, we expect some fields to exist in this
channel
field, particularlyid
+type
(andname
+parent_id
+thread_metadata
in the case of threads)While all these are documented to exist in
interaction.resolved.channels
, this might not be the case forinteraction.channel
, which really only guaranteesid
andtype
.In the end it's probably a fair assumption, but still something we should improve in the future.
related thread
Checklist
pdm lint
pdm pyright