Skip to content

Commit 6d74aa7

Browse files
Add missing permissions function
Get single guild command permissions endpoint was missing from manage_commands, it's not used by the library but this is meant to be a utility file
1 parent 85c1820 commit 6d74aa7

File tree

1 file changed

+27
-0
lines changed

1 file changed

+27
-0
lines changed

discord_slash/utils/manage_commands.py

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -166,6 +166,33 @@ async def get_all_guild_commands_permissions(bot_id,
166166
raise RequestFailure(resp.status, await resp.text())
167167
return await resp.json()
168168

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
175+
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,

0 commit comments

Comments
 (0)