diff --git a/discord/app_commands/models.py b/discord/app_commands/models.py index 5851e7d8c..704905d75 100644 --- a/discord/app_commands/models.py +++ b/discord/app_commands/models.py @@ -394,6 +394,39 @@ class AppCommand(Hashable): ) 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: """|coro| diff --git a/discord/http.py b/discord/http.py index 7d59c8bfb..613ec3b35 100644 --- a/discord/http.py +++ b/discord/http.py @@ -2288,7 +2288,7 @@ class HTTPClient: self, application_id: Snowflake, guild_id: Snowflake, - payload: Dict[str, Any], + payload: command.ApplicationCommand, ) -> Response[command.ApplicationCommand]: r = Route( 'POST',