Skip to content

Commit e950add

Browse files
authored
Merge pull request #199 from eunwoo1104/AnotherCat-fix-manage_commands
Fix manage commands
2 parents f5baaeb + 6d74aa7 commit e950add

File tree

1 file changed

+34
-6
lines changed

1 file changed

+34
-6
lines changed

discord_slash/utils/manage_commands.py

Lines changed: 34 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -147,15 +147,15 @@ async def get_all_guild_commands_permissions(bot_id,
147147
bot_token,
148148
guild_id):
149149
"""
150-
A coroutine that sends a slash command get request to Discord API.
150+
A coroutine that sends a gets all the commands permissions for that guild.
151151
152152
:param bot_id: User ID of the bot.
153153
:param bot_token: Token of the bot.
154154
:param guild_id: ID of the guild to get permissions.
155155
:return: JSON Response of the request. A list of <https://discord.com/developers/docs/interactions/slash-commands#get-application-command-permissions>.
156156
:raises: :class:`.error.RequestFailure` - Requesting to Discord API has failed.
157157
"""
158-
url = f"https://discord.com/api/v8/applications/{bot_id}/guilds/{guild_id}/permissions"
158+
url = f"https://discord.com/api/v8/applications/{bot_id}/guilds/{guild_id}/commands/permissions"
159159
async with aiohttp.ClientSession() as session:
160160
async with session.get(url, headers={"Authorization": f"Bot {bot_token}"}) as resp:
161161
if resp.status == 429:
@@ -165,15 +165,42 @@ async def get_all_guild_commands_permissions(bot_id,
165165
if not 200 <= resp.status < 300:
166166
raise RequestFailure(resp.status, await resp.text())
167167
return await resp.json()
168+
169+
async def get_guild_command_permissions(bot_id,
170+
bot_token,
171+
guild_id,
172+
command_id):
173+
"""
174+
A coroutine that sends a request to get a single command's permissions in guild
168175
176+
:param bot_id: User ID of the bot.
177+
:param bot_token: Token of the bot.
178+
:param guild_id: ID of the guild to update permissions on.
179+
:param command_id: ID for the command to update permissions on.
180+
:param permissions: List of permissions for the command.
181+
:return: JSON Response of the request. A list of <https://discord.com/developers/docs/interactions/slash-commands#edit-application-command-permissions>
182+
:raises: :class:`.error.RequestFailure` - Requesting to Discord API has failed.
183+
"""
184+
url = f"https://discord.com/api/v8/applications/{bot_id}/guilds/{guild_id}/commands/{command_id}/permissions"
185+
async with aiohttp.ClientSession() as session:
186+
async with session.get(url, headers={"Authorization": f"Bot {bot_token}"}) as resp:
187+
if resp.status == 429:
188+
_json = await resp.json()
189+
await asyncio.sleep(_json["retry_after"])
190+
return await get_guild_command_permissions(bot_id, bot_token, guild_id)
191+
if not 200 <= resp.status < 300:
192+
raise RequestFailure(resp.status, await resp.text())
193+
return await resp.json()
194+
195+
169196

170197
async def update_single_command_permissions(bot_id,
171198
bot_token,
172199
guild_id,
173200
command_id,
174201
permissions):
175202
"""
176-
A coroutine that sends a slash command put request to Discord API.
203+
A coroutine that sends a request to update a single command's permissions in guild
177204
178205
:param bot_id: User ID of the bot.
179206
:param bot_token: Token of the bot.
@@ -189,18 +216,19 @@ async def update_single_command_permissions(bot_id,
189216
if resp.status == 429:
190217
_json = await resp.json()
191218
await asyncio.sleep(_json["retry_after"])
192-
return await update_guild_commands_permissions(bot_id, bot_token, guild_id, permissions)
219+
return await update_single_command_permissions(bot_id, bot_token, guild_id, permissions)
193220
if not 200 <= resp.status < 300:
194221
raise RequestFailure(resp.status, await resp.text())
195222
return await resp.json()
196223

197224

225+
198226
async def update_guild_commands_permissions(bot_id,
199227
bot_token,
200228
guild_id,
201229
cmd_permissions):
202230
"""
203-
A coroutine that sends a slash command put request to Discord API.
231+
A coroutine that updates permissions for all commands in a guild.
204232
205233
:param bot_id: User ID of the bot.
206234
:param bot_token: Token of the bot.
@@ -209,7 +237,7 @@ async def update_guild_commands_permissions(bot_id,
209237
:return: JSON Response of the request. A list of <https://discord.com/developers/docs/interactions/slash-commands#batch-edit-application-command-permissions>.
210238
:raises: :class:`.error.RequestFailure` - Requesting to Discord API has failed.
211239
"""
212-
url = f"https://discord.com/api/v8/applications/{bot_id}/guilds/{guild_id}/permissions"
240+
url = f"https://discord.com/api/v8/applications/{bot_id}/guilds/{guild_id}/commands/permissions"
213241
async with aiohttp.ClientSession() as session:
214242
async with session.put(url, headers={"Authorization": f"Bot {bot_token}"}, json=cmd_permissions) as resp:
215243
if resp.status == 429:

0 commit comments

Comments
 (0)