Skip to content

Commit 1f6ce42

Browse files
authored
Merge pull request #113 from DXsmiley/master
Add override for the application ID in order to support legacy applications
2 parents 2a9ebcf + 22853f8 commit 1f6ce42

File tree

2 files changed

+14
-8
lines changed

2 files changed

+14
-8
lines changed

discord_slash/client.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -45,12 +45,13 @@ def __init__(self,
4545
sync_commands: bool = False,
4646
delete_from_unused_guilds: bool = False,
4747
sync_on_cog_reload: bool = False,
48-
override_type: bool = False):
48+
override_type: bool = False,
49+
application_id: typing.Optional[int] = None):
4950
self._discord = client
5051
self.commands = {}
5152
self.subcommands = {}
5253
self.logger = logging.getLogger("discord_slash")
53-
self.req = http.SlashCommandRequest(self.logger, self._discord)
54+
self.req = http.SlashCommandRequest(self.logger, self._discord, application_id)
5455
self.sync_commands = sync_commands
5556
self.sync_on_cog_reload = sync_on_cog_reload
5657

discord_slash/http.py

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -11,9 +11,14 @@ class CustomRoute(Route):
1111

1212

1313
class SlashCommandRequest:
14-
def __init__(self, logger, _discord):
14+
def __init__(self, logger, _discord, application_id):
1515
self.logger = logger
1616
self._discord: typing.Union[discord.Client, discord.AutoShardedClient] = _discord
17+
self._application_id = application_id
18+
19+
@property
20+
def application_id(self):
21+
return self._application_id or self._discord.user.id
1722

1823
def put_slash_commands(self, slash_commands: list, guild_id):
1924
"""
@@ -72,7 +77,7 @@ def command_request(self, method, guild_id, url_ending="", **kwargs):
7277
:param url_ending: String to append onto the end of the url.
7378
:param \**kwargs: Kwargs to pass into discord.py's `request function <https://github.com/Rapptz/discord.py/blob/master/discord/http.py#L134>`_
7479
"""
75-
url = f"/applications/{self._discord.user.id}"
80+
url = f"/applications/{self.application_id}"
7681
url += "/commands" if not guild_id else f"/guilds/{guild_id}/commands"
7782
url += url_ending
7883
route = CustomRoute(method, url)
@@ -93,12 +98,12 @@ def post(self, _resp, interaction_id, token, initial=False, files: typing.List[d
9398
"""
9499
if files:
95100
return self.post_with_files(_resp, files, token)
96-
req_url = f"/interactions/{interaction_id}/{token}/callback" if initial else f"/webhooks/{self._discord.user.id}/{token}"
101+
req_url = f"/interactions/{interaction_id}/{token}/callback" if initial else f"/webhooks/{self.application_id}/{token}"
97102
route = CustomRoute("POST", req_url)
98103
return self._discord.http.request(route, json=_resp)
99104

100105
def post_with_files(self, _resp, files: typing.List[discord.File], token):
101-
req_url = f"/webhooks/{self._discord.user.id}/{token}"
106+
req_url = f"/webhooks/{self.application_id}/{token}"
102107
route = CustomRoute("POST", req_url)
103108
form = aiohttp.FormData()
104109
form.add_field("payload_json", json.dumps(_resp))
@@ -118,7 +123,7 @@ def edit(self, _resp, token, message_id="@original"):
118123
:param message_id: Message ID to edit. Default initial message.
119124
:return: Coroutine
120125
"""
121-
req_url = f"/webhooks/{self._discord.user.id}/{token}/messages/{message_id}"
126+
req_url = f"/webhooks/{self.application_id}/{token}/messages/{message_id}"
122127
route = CustomRoute("PATCH", req_url)
123128
return self._discord.http.request(route, json=_resp)
124129

@@ -130,6 +135,6 @@ def delete(self, token, message_id="@original"):
130135
:param message_id: Message ID to delete. Default initial message.
131136
:return: Coroutine
132137
"""
133-
req_url = f"/webhooks/{self._discord.user.id}/{token}/messages/{message_id}"
138+
req_url = f"/webhooks/{self.application_id}/{token}/messages/{message_id}"
134139
route = CustomRoute("DELETE", req_url)
135140
return self._discord.http.request(route)

0 commit comments

Comments
 (0)