parent
ee6f4e85d6
commit
6ed0ae7d96
@ -229,8 +229,8 @@ class Invite(Hashable):
|
||||
How long the before the invite expires in seconds. A value of 0 indicates that it doesn't expire.
|
||||
code: :class:`str`
|
||||
The URL fragment used for the invite.
|
||||
guild: Union[:class:`Guild`, :class:`Object`, :class:`PartialInviteGuild`]
|
||||
The guild the invite is for.
|
||||
guild: Optional[Union[:class:`Guild`, :class:`Object`, :class:`PartialInviteGuild`]]
|
||||
The guild the invite is for. Can be ``None`` if it's from a group direct message.
|
||||
revoked: :class:`bool`
|
||||
Indicates if the invite has been revoked.
|
||||
created_at: :class:`datetime.datetime`
|
||||
@ -278,17 +278,28 @@ class Invite(Hashable):
|
||||
|
||||
@classmethod
|
||||
def from_incomplete(cls, *, state, data):
|
||||
guild_id = int(data['guild']['id'])
|
||||
channel_id = int(data['channel']['id'])
|
||||
guild = state._get_guild(guild_id)
|
||||
if guild is not None:
|
||||
channel = guild.get_channel(channel_id)
|
||||
try:
|
||||
guild_id = int(data['guild']['id'])
|
||||
except KeyError:
|
||||
# If we're here, then this is a group DM
|
||||
guild = None
|
||||
else:
|
||||
channel_data = data['channel']
|
||||
guild_data = data['guild']
|
||||
channel_type = try_enum(ChannelType, channel_data['type'])
|
||||
channel = PartialInviteChannel(id=channel_id, name=channel_data['name'], type=channel_type)
|
||||
guild = PartialInviteGuild(state, guild_data, guild_id)
|
||||
guild = state._get_guild(guild_id)
|
||||
if guild is None:
|
||||
# If it's not cached, then it has to be a partial guild
|
||||
guild_data = data['guild']
|
||||
guild = PartialInviteGuild(state, guild_data, guild_id)
|
||||
|
||||
# As far as I know, invites always need a channel
|
||||
# So this should never raise.
|
||||
channel_data = data['channel']
|
||||
channel_id = int(channel_data['id'])
|
||||
channel_type = try_enum(ChannelType, channel_data['type'])
|
||||
channel = PartialInviteChannel(id=channel_id, name=channel_data['name'], type=channel_type)
|
||||
if guild is not None:
|
||||
# Upgrade the partial data if applicable
|
||||
channel = guild.get_channel(channel_id) or channel
|
||||
|
||||
data['guild'] = guild
|
||||
data['channel'] = channel
|
||||
return cls(state=state, data=data)
|
||||
|
Loading…
x
Reference in New Issue
Block a user