diff options
| author | Rapptz <[email protected]> | 2021-06-28 01:03:46 -0400 |
|---|---|---|
| committer | Rapptz <[email protected]> | 2021-06-28 01:03:46 -0400 |
| commit | a75cd93acc00ba187ce6317dd0567ac12e817433 (patch) | |
| tree | 1b91682a33f16bf0f1fcf38b31c895fcb4d1f9e1 | |
| parent | Type-hint voice_client / player (diff) | |
| download | discord.py-a75cd93acc00ba187ce6317dd0567ac12e817433.tar.xz discord.py-a75cd93acc00ba187ce6317dd0567ac12e817433.zip | |
Fix Guild.vanity_invite causing an error when guild has it unset
FIx #7103
| -rw-r--r-- | discord/guild.py | 10 |
1 files changed, 7 insertions, 3 deletions
diff --git a/discord/guild.py b/discord/guild.py index 67d41d80..024aa5d8 100644 --- a/discord/guild.py +++ b/discord/guild.py @@ -2407,7 +2407,7 @@ class Guild(Hashable): """ await self._state.http.unban(user.id, self.id, reason=reason) - async def vanity_invite(self) -> Invite: + async def vanity_invite(self) -> Optional[Invite]: """|coro| Returns the guild's special vanity invite. @@ -2426,12 +2426,15 @@ class Guild(Hashable): Returns -------- - :class:`Invite` - The special vanity invite. + Optional[:class:`Invite`] + The special vanity invite. If ``None`` then the guild does not + have a vanity invite set. """ # we start with { code: abc } payload = await self._state.http.get_vanity_code(self.id) + if not payload['code']: + return None # get the vanity URL channel since default channels aren't # reliable or a thing anymore @@ -2442,6 +2445,7 @@ class Guild(Hashable): payload['temporary'] = False payload['max_uses'] = 0 payload['max_age'] = 0 + payload['uses'] = payload.get('uses', 0) return Invite(state=self._state, data=payload, guild=self, channel=channel) # TODO: use MISSING when async iterators get refactored |