aboutsummaryrefslogtreecommitdiff
path: root/discord/invite.py
diff options
context:
space:
mode:
authorRapptz <[email protected]>2020-01-17 19:15:49 -0500
committerRapptz <[email protected]>2020-01-17 19:20:53 -0500
commit7b2c01c48a93a834c5cf9f0858b41f172431ce67 (patch)
tree3348dec9d580befe4222c4889eaac9de45bf37d8 /discord/invite.py
parentMake CustomActivity.__str__ not raise errors and match the client (diff)
downloaddiscord.py-7b2c01c48a93a834c5cf9f0858b41f172431ce67.tar.xz
discord.py-7b2c01c48a93a834c5cf9f0858b41f172431ce67.zip
Add support for on_invite_create and on_invite_delete
Diffstat (limited to 'discord/invite.py')
-rw-r--r--discord/invite.py22
1 files changed, 19 insertions, 3 deletions
diff --git a/discord/invite.py b/discord/invite.py
index 28458b7a..a70d39e4 100644
--- a/discord/invite.py
+++ b/discord/invite.py
@@ -25,7 +25,8 @@ DEALINGS IN THE SOFTWARE.
"""
from .asset import Asset
-from .utils import parse_time, snowflake_time
+from .utils import parse_time, snowflake_time, _get_as_snowflake
+from .object import Object
from .mixins import Hashable
from .enums import ChannelType, VerificationLevel, try_enum
from collections import namedtuple
@@ -228,7 +229,7 @@ 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:`PartialInviteGuild`]
+ guild: Union[:class:`Guild`, :class:`Object`, :class:`PartialInviteGuild`]
The guild the invite is for.
revoked: :class:`bool`
Indicates if the invite has been revoked.
@@ -248,7 +249,7 @@ class Invite(Hashable):
approximate_presence_count: Optional[:class:`int`]
The approximate number of members currently active in the guild.
This includes idle, dnd, online, and invisible members. Offline members are excluded.
- channel: Union[:class:`abc.GuildChannel`, :class:`PartialInviteChannel`]
+ channel: Union[:class:`abc.GuildChannel`, :class:`Object`, :class:`PartialInviteChannel`]
The channel the invite is for.
"""
@@ -292,6 +293,21 @@ class Invite(Hashable):
data['channel'] = channel
return cls(state=state, data=data)
+ @classmethod
+ def from_gateway(cls, *, state, data):
+ guild_id = _get_as_snowflake(data, 'guild_id')
+ guild = state._get_guild(guild_id)
+ channel_id = _get_as_snowflake(data, 'channel_id')
+ if guild is not None:
+ channel = guild.get_channel(channel_id) or Object(id=channel_id)
+ else:
+ guild = Object(id=guild_id)
+ channel = Object(id=channel_id)
+
+ data['guild'] = guild
+ data['channel'] = channel
+ return cls(state=state, data=data)
+
def __str__(self):
return self.url