Skip to content

Commit 968557d

Browse files
committed
Move functions to utils.manage_commands
1 parent 2ed9d9f commit 968557d

File tree

2 files changed

+46
-39
lines changed

2 files changed

+46
-39
lines changed

discord_slash/client.py

Lines changed: 0 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -167,45 +167,6 @@ async def register_all_commands(self):
167167
selected.options)
168168
self.logger.info("Completed registering all commands!")
169169

170-
async def remove_all_commands(self):
171-
"""
172-
Remove all slash commands.
173-
"""
174-
175-
await self.remove_all_commands_in('global')
176-
177-
for guild in self._discord.guilds:
178-
try: await self.remove_all_commands_in(guild.id)
179-
except error.RequestFailure:
180-
pass
181-
182-
async def remove_all_commands_in(self, area):
183-
"""
184-
Remove all slash commands in area.
185-
186-
:param area: 'global' or guild ID where removing all commands.
187-
:type area: Union[str, int]
188-
"""
189-
await self._discord.wait_until_ready() # In case commands are still not registered to SlashCommand.
190-
191-
self.logger.info("Removing commands...")
192-
193-
commands = await manage_commands.get_all_commands(
194-
self._discord.user.id,
195-
self._discord.http.token,
196-
None if area == 'global' else area
197-
)
198-
199-
for command in commands:
200-
await manage_commands.remove_slash_command(
201-
self._discord.user.id,
202-
self._discord.http.token,
203-
None if area == 'global' else area,
204-
command['id']
205-
)
206-
207-
self.logger.info("Completed removing all commands !")
208-
209170
def add_slash_command(self,
210171
cmd,
211172
name: str = None,

discord_slash/utils/manage_commands.py

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -93,6 +93,52 @@ async def get_all_commands(bot_id,
9393
return await resp.json()
9494

9595

96+
async def remove_all_commands(slash):
97+
"""
98+
Remove all slash commands.
99+
100+
:param slash: Instance of SlashCommand.
101+
:type slash: SlashCommand
102+
"""
103+
104+
await remove_all_commands_in(slash, 'global')
105+
106+
for guild in slash._discord.guilds:
107+
try: await remove_all_commands_in(slash, guild.id)
108+
except RequestFailure:
109+
pass
110+
111+
112+
async def remove_all_commands_in(slash, area):
113+
"""
114+
Remove all slash commands in area.
115+
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]
120+
"""
121+
await slash._discord.wait_until_ready() # In case commands are still not registered to SlashCommand.
122+
123+
slash.logger.info("Removing commands...")
124+
125+
commands = await get_all_commands(
126+
slash._discord.user.id,
127+
slash._discord.http.token,
128+
None if area == 'global' else area
129+
)
130+
131+
for command in commands:
132+
await remove_slash_command(
133+
slash._discord.user.id,
134+
slash._discord.http.token,
135+
None if area == 'global' else area,
136+
command['id']
137+
)
138+
139+
slash.logger.info("Completed removing all commands !")
140+
141+
96142
def create_option(name: str,
97143
description: str,
98144
option_type: int,

0 commit comments

Comments
 (0)