feat(RESTApp): add edit_global_application_command() method

This commit is contained in:
Victor Kotlin 2022-06-14 16:44:32 +03:00
parent 3eeefb5beb
commit e3ea442bc8
2 changed files with 97 additions and 3 deletions

View file

@ -231,7 +231,7 @@ class HTTPClient:
return await self.__send("DELETE", route, headers=headers) return await self.__send("DELETE", route, headers=headers)
async def patch( async def patch(
self, route: str, *, headers: dict = None, data: Optional[Dict] = None self, route: str, *, headers: dict = None, json: Optional[Dict] = None, data=None
) -> Optional[Dict]: ) -> Optional[Dict]:
"""|coro| """|coro|
Sends a PATCH request to a Discord REST API endpoint. Sends a PATCH request to a Discord REST API endpoint.
@ -240,8 +240,10 @@ class HTTPClient:
---------- ----------
route : :class:`str` route : :class:`str`
The endpoint to send the request to. The endpoint to send the request to.
data : Dict data : Any
Data to post Data to post
json: Dict
Json data to post
headers : :class:`dict` headers : :class:`dict`
Custom request headers Custom request headers
@ -250,7 +252,7 @@ class HTTPClient:
Optional[:class:`Dict`] Optional[:class:`Dict`]
JSON response from the Discord API. JSON response from the Discord API.
""" """
return await self.__send("PATCH", route, json=data, headers=headers) return await self.__send("PATCH", route, json=json, data=data, headers=headers)
async def put( async def put(
self, route: str, *, headers: dict = None, data: Optional[Dict] = None self, route: str, *, headers: dict = None, data: Optional[Dict] = None

View file

@ -822,6 +822,98 @@ class RESTApp:
) )
) )
async def edit_global_application_command(
self,
application_id: Union[int, str, Snowflake],
command_id: Union[int, str, Snowflake],
*,
name: Optional[str] = None,
description: Optional[str] = None,
name_localizations: Optional[Dict[str, str]] = None,
description_localizations: Optional[Dict[str, str]] = None,
options: Optional[List[ApplicationCommandOption]] = None,
default_member_permissions: Optional[str] = None,
dm_permission: Optional[bool] = None,
default_permission: Optional[bool] = None,
):
"""|coro|
All parameters are optional, but any parameters
provided will entirely overwrite the existing values of those parameters.
[**REST API**] Edit a global command.
Parameters
----------
application_id: :class:`~melisa.utils.snowflake.Snowflake`
ID of the parent application
command_id: Optional[bool]
ID of command to edit.
name: Optional[str]
Name of command, 1-32 characters
description: Optional[str]
Description for ``CHAT_INPUT`` commands, 1-100 characters.
Empty string for ``USER`` and ``MESSAGE`` commands
name_localizations: Optional[Dict[str, str]]
Localization dictionary for ``name`` field.
Values follow the same restrictions as ``name``
description_localizations: Optional[Dict[str, str]]
Localization dictionary for ``description`` field.
Values follow the same restrictions as ``description``
options: Optional[List[:class:`~melisa.models.interactions.commands.ApplicationCommandOption`]]
Parameters for the command, max of 25.
Only available for ``CHAT_INPUT`` command type.
default_member_permissions: Optional[str]
Set of permissions represented as a bit set
dm_permission: Optional[bool]
Indicates whether the command is available
in DMs with the app, only for globally-scoped commands.
By default, commands are visible.
default_permission: Optional[bool]
Not recommended for use as field will soon be deprecated.
Indicates whether the command is enabled by default
when the app is added to a guild, defaults to true
Raises
-------
HTTPException
The request to perform the action failed with other http exception.
ForbiddenError
You do not have proper permissions to do the actions required.
BadRequestError
You provided a wrong arguments
"""
data = {}
if name is not None:
data["name"] = name
if description is not None:
data["description"] = description
if name_localizations is not None:
data["name_localizations"] = name_localizations
if description_localizations is not None:
data["description_localizations"] = description_localizations
if default_member_permissions is not None:
data["default_member_permissions"] = default_member_permissions
if options is not None:
data["options"] = [x.to_dict() for x in options]
if dm_permission is not None:
data["dm_permission"] = dm_permission
if default_permission is not None:
data["default_permission"] = default_permission
return ApplicationCommand.from_dict(
await self._http.patch(f"/applications/{application_id}/commands/{command_id}", json=data)
)
class CDNBuilder: class CDNBuilder:
"""Can be used to build images """Can be used to build images