Browse Source

Add ability to upsert single AppCommand

pull/10216/head
Soheab_ 4 weeks ago
parent
commit
865441f00a
  1. 33
      discord/app_commands/models.py
  2. 2
      discord/http.py

33
discord/app_commands/models.py

@ -394,6 +394,39 @@ class AppCommand(Hashable):
) )
return AppCommand(data=data, state=state) return AppCommand(data=data, state=state)
async def sync(
self,
) -> AppCommand:
"""|coro|
Syncs the application command to Discord.
Raises
-------
HTTPException
Syncing the commands failed.
Forbidden
The client does not have the ``applications.commands`` scope in the guild.
MissingApplicationID
The client does not have an application ID.
Returns
--------
:class:`AppCommand`
The application command that got synced.
"""
state = self._state
if not state.application_id:
raise MissingApplicationID
payload = self.to_dict()
if self.guild_id:
data = await state.http.upsert_guild_command(state.application_id, self.guild_id, payload=payload)
else:
data = await state.http.upsert_global_command(state.application_id, payload=payload)
return AppCommand(data=data, state=state)
async def fetch_permissions(self, guild: Snowflake) -> GuildAppCommandPermissions: async def fetch_permissions(self, guild: Snowflake) -> GuildAppCommandPermissions:
"""|coro| """|coro|

2
discord/http.py

@ -2288,7 +2288,7 @@ class HTTPClient:
self, self,
application_id: Snowflake, application_id: Snowflake,
guild_id: Snowflake, guild_id: Snowflake,
payload: Dict[str, Any], payload: command.ApplicationCommand,
) -> Response[command.ApplicationCommand]: ) -> Response[command.ApplicationCommand]:
r = Route( r = Route(
'POST', 'POST',

Loading…
Cancel
Save