Browse Source

Update create invite parameters

pull/10109/head
dolfies 2 years ago
parent
commit
31c31ce030
  1. 20
      discord/abc.py
  2. 8
      discord/http.py
  3. 2
      discord/invite.py

20
discord/abc.py

@ -1260,9 +1260,10 @@ class GuildChannel:
max_uses: int = 0, max_uses: int = 0,
temporary: bool = False, temporary: bool = False,
unique: bool = True, unique: bool = True,
validate: Optional[Union[Invite, str]],
target_type: Optional[InviteTarget] = None, target_type: Optional[InviteTarget] = None,
target_user: Optional[User] = None, target_user: Optional[User] = None,
target_application_id: Optional[int] = None, target_application: Optional[Snowflake] = None,
) -> Invite: ) -> Invite:
"""|coro| """|coro|
@ -1286,8 +1287,11 @@ class GuildChannel:
Indicates if a unique invite URL should be created. Defaults to True. Indicates if a unique invite URL should be created. Defaults to True.
If this is set to ``False`` then it will return a previously created If this is set to ``False`` then it will return a previously created
invite. invite.
reason: Optional[:class:`str`] validate: Union[:class:`Invite`, :class:`str`]
The reason for creating this invite. Shows up on the audit log. The existing channel invite to validate and return for reuse.
If this invite is invalid, a new invite will be created according to the parameters and returned.
.. versionadded:: 2.0
target_type: Optional[:class:`.InviteTarget`] target_type: Optional[:class:`.InviteTarget`]
The type of target for the voice channel invite, if any. The type of target for the voice channel invite, if any.
@ -1298,11 +1302,14 @@ class GuildChannel:
.. versionadded:: 2.0 .. versionadded:: 2.0
target_application_id:: Optional[:class:`int`] target_application:: Optional[:class:`Application`]
The id of the embedded application for the invite, required if `target_type` is `TargetType.embedded_application`. The embedded application for the invite, required if `target_type` is `TargetType.embedded_application`.
.. versionadded:: 2.0 .. versionadded:: 2.0
reason: Optional[:class:`str`]
The reason for creating this invite. Shows up on the audit log.
Raises Raises
------- -------
~discord.HTTPException ~discord.HTTPException
@ -1323,9 +1330,10 @@ class GuildChannel:
max_uses=max_uses, max_uses=max_uses,
temporary=temporary, temporary=temporary,
unique=unique, unique=unique,
validate=utils.resolve_invite(validate).code if validate else None,
target_type=target_type.value if target_type else None, target_type=target_type.value if target_type else None,
target_user_id=target_user.id if target_user else None, target_user_id=target_user.id if target_user else None,
target_application_id=target_application_id, target_application_id=target_application.id if target_application else None,
) )
return Invite.from_incomplete(data=data, state=self._state) return Invite.from_incomplete(data=data, state=self._state)

8
discord/http.py

@ -1792,6 +1792,7 @@ class HTTPClient:
max_uses: int = 0, max_uses: int = 0,
temporary: bool = False, temporary: bool = False,
unique: bool = True, unique: bool = True,
validate: Optional[str] = None,
target_type: Optional[invite.InviteTargetType] = None, target_type: Optional[invite.InviteTargetType] = None,
target_user_id: Optional[Snowflake] = None, target_user_id: Optional[Snowflake] = None,
target_application_id: Optional[Snowflake] = None, target_application_id: Optional[Snowflake] = None,
@ -1799,11 +1800,12 @@ class HTTPClient:
payload = { payload = {
'max_age': max_age, 'max_age': max_age,
'max_uses': max_uses, 'max_uses': max_uses,
'target_type': target_type,
'temporary': temporary, 'temporary': temporary,
'unique': unique, 'validate': validate,
} }
if target_type: if unique:
payload['target_type'] = target_type payload['unique'] = unique
if target_user_id: if target_user_id:
payload['target_user_id'] = target_user_id payload['target_user_id'] = target_user_id
if target_application_id: if target_application_id:

2
discord/invite.py

@ -530,7 +530,7 @@ class Invite(Hashable):
channel_data = data.get('channel') channel_data = data.get('channel')
if channel_data and channel_data.get('type') == ChannelType.private.value: if channel_data and channel_data.get('type') == ChannelType.private.value:
channel_data['recipients'] = [data['inviter']] if 'inviter' in data else [] channel_data['recipients'] = [data['inviter']] if 'inviter' in data else [] # type: ignore
channel = PartialInviteChannel(channel_data, state) channel = PartialInviteChannel(channel_data, state)
channel = state.get_channel(getattr(channel, 'id', None)) or channel channel = state.get_channel(getattr(channel, 'id', None)) or channel

Loading…
Cancel
Save