Skip to content

Commit 0ee2034

Browse files
Merge branch 'master' into new-ui-changes
2 parents 498ce91 + c386b6f commit 0ee2034

File tree

5 files changed

+250
-99
lines changed

5 files changed

+250
-99
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 & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,9 +12,14 @@ class CustomRoute(Route):
1212

1313

1414
class SlashCommandRequest:
15-
def __init__(self, logger, _discord):
15+
def __init__(self, logger, _discord, application_id):
1616
self.logger = logger
1717
self._discord: typing.Union[discord.Client, discord.AutoShardedClient] = _discord
18+
self._application_id = application_id
19+
20+
@property
21+
def application_id(self):
22+
return self._application_id or self._discord.user.id
1823

1924
def put_slash_commands(self, slash_commands: list, guild_id):
2025
"""
@@ -73,7 +78,7 @@ def command_request(self, method, guild_id, url_ending="", **kwargs):
7378
:param url_ending: String to append onto the end of the url.
7479
:param \**kwargs: Kwargs to pass into discord.py's `request function <https://github.com/Rapptz/discord.py/blob/master/discord/http.py#L134>`_
7580
"""
76-
url = f"/applications/{self._discord.user.id}"
81+
url = f"/applications/{self.application_id}"
7782
url += "/commands" if not guild_id else f"/guilds/{guild_id}/commands"
7883
url += url_ending
7984
route = CustomRoute(method, url)
@@ -120,12 +125,13 @@ def command_response(self, token, use_webhook, method, interaction_id= None, url
120125
"""
121126
if not use_webhook and not interaction_id:
122127
raise error.IncorrectFormat("Internal Error! interaction_id must be set if use_webhook is False")
123-
req_url = f"/webhooks/{self._discord.user.id}/{token}" if use_webhook else f"/interactions/{interaction_id}/{token}/callback"
128+
req_url = f"/webhooks/{self.application_id}/{token}" if use_webhook else f"/interactions/{interaction_id}/{token}/callback"
124129
req_url += url_ending
125130
route = CustomRoute(method, req_url)
126131
return self._discord.http.request(route, **kwargs)
127132

128133
def post_with_files(self, _resp, files: typing.List[discord.File], token):
134+
129135
form = aiohttp.FormData()
130136
form.add_field("payload_json", json.dumps(_resp))
131137
for x in range(len(files)):
@@ -147,6 +153,7 @@ def edit(self, _resp, token, message_id="@original"):
147153
req_url = f"/messages/{message_id}"
148154
return self.command_response(token, True, "PATCH", url_ending = req_url, json=_resp)
149155

156+
150157
def delete(self, token, message_id="@original"):
151158
"""
152159
Sends delete command response POST request to Discord API.
@@ -157,3 +164,4 @@ def delete(self, token, message_id="@original"):
157164
"""
158165
req_url = f"/messages/{message_id}"
159166
return self.command_response(token, True, "DELETE", url_ending = req_url)
167+

0 commit comments

Comments
 (0)