Skip to content

Commit

Permalink
Fix Guild.vanity_invite causing an error when guild has it unset
Browse files Browse the repository at this point in the history
FIx #7103
  • Loading branch information
Rapptz committed Jun 28, 2021
1 parent 5acea45 commit a75cd93
Showing 1 changed file with 7 additions and 3 deletions.
10 changes: 7 additions & 3 deletions discord/guild.py
Original file line number Diff line number Diff line change
Expand Up @@ -2407,7 +2407,7 @@ async def unban(self, user: Snowflake, *, reason: Optional[str] = None) -> None:
"""
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.
Expand All @@ -2426,12 +2426,15 @@ async def vanity_invite(self) -> Invite:
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
Expand All @@ -2442,6 +2445,7 @@ async def vanity_invite(self) -> Invite:
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
Expand Down

0 comments on commit a75cd93

Please sign in to comment.