Skip to content

Commit baf3f7e

Browse files
committed
Some changes to #41
1 parent abdf0a8 commit baf3f7e

File tree

1 file changed

+24
-25
lines changed

1 file changed

+24
-25
lines changed

discord_slash/utils/manage_commands.py

Lines changed: 24 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -93,51 +93,50 @@ async def get_all_commands(bot_id,
9393
return await resp.json()
9494

9595

96-
async def remove_all_commands(slash):
96+
async def remove_all_commands(bot_id,
97+
bot_token,
98+
guild_ids):
9799
"""
98100
Remove all slash commands.
99101
100-
:param slash: Instance of SlashCommand.
101-
:type slash: SlashCommand
102+
:param bot_id: User ID of the bot.
103+
:param bot_token: Token of the bot.
104+
:param guild_ids: List ID of the guild to remove commands.
102105
"""
103106

104-
await remove_all_commands_in(slash, 'global')
107+
await remove_all_commands_in(bot_id, bot_token, None)
105108

106-
for guild in slash._discord.guilds:
107-
try: await remove_all_commands_in(slash, guild.id)
109+
for x in guild_ids:
110+
try:
111+
await remove_all_commands_in(bot_id, bot_token, x)
108112
except RequestFailure:
109113
pass
110114

111115

112-
async def remove_all_commands_in(slash, area):
116+
async def remove_all_commands_in(bot_id,
117+
bot_token,
118+
guild_id=None):
113119
"""
114120
Remove all slash commands in area.
115121
116-
:param slash: Instance of SlashCommand.
117-
:type slash: SlashCommand
118-
:param area: 'global' or guild ID where removing all commands.
119-
:type area: Union[str, int]
122+
:param bot_id: User ID of the bot.
123+
:param bot_token: Token of the bot.
124+
:param guild_id: ID of the guild to remove commands. Pass `None` to remove all global commands.
120125
"""
121-
await slash._discord.wait_until_ready() # In case commands are still not registered to SlashCommand.
122-
123-
slash.logger.info("Removing commands...")
124-
125126
commands = await get_all_commands(
126-
slash._discord.user.id,
127-
slash._discord.http.token,
128-
None if area == 'global' else area
127+
bot_id,
128+
bot_token,
129+
guild_id
129130
)
130131

131-
for command in commands:
132+
for x in commands:
132133
await remove_slash_command(
133-
slash._discord.user.id,
134-
slash._discord.http.token,
135-
None if area == 'global' else area,
136-
command['id']
134+
bot_id,
135+
bot_token,
136+
guild_id,
137+
x['id']
137138
)
138139

139-
slash.logger.info("Completed removing all commands !")
140-
141140

142141
def create_option(name: str,
143142
description: str,

0 commit comments

Comments
 (0)