Move slash command creation to BotBase

This commit is contained in:
Gnome 2021-09-06 20:05:06 +01:00
parent bc2725dacc
commit 17096629cd

View File

@ -248,7 +248,10 @@ class BotBase(GroupMixin):
for event in self.extra_events.get(ev, []):
self._schedule_event(event, ev, *args, **kwargs) # type: ignore
async def _create_application_commands(self, application_id: int, http: HTTPClient):
async def setup(self):
await self.create_slash_commands()
async def create_slash_commands(self):
commands: defaultdict[Optional[int], List[EditApplicationCommand]] = defaultdict(list)
for command in self.commands:
if command.hidden or (command.slash_command is None and not self.slash_commands):
@ -269,7 +272,9 @@ class BotBase(GroupMixin):
for guild in guilds:
commands[guild].append(payload)
http: HTTPClient = self.http # type: ignore
global_commands = commands.pop(None, None)
application_id = self.application_id or (await self.application_info()).id # type: ignore
if global_commands is not None:
if self.slash_command_guilds is None:
await http.bulk_upsert_global_commands(
@ -1385,9 +1390,7 @@ class Bot(BotBase, discord.Client):
"""
async def setup(self):
application = self.application_id or (await self.application_info()).id
await self._create_application_commands(application, self.http)
pass
class AutoShardedBot(BotBase, discord.AutoShardedClient):
@ -1395,6 +1398,4 @@ class AutoShardedBot(BotBase, discord.AutoShardedClient):
:class:`discord.AutoShardedClient` instead.
"""
async def setup(self):
application = self.application_id or (await self.application_info()).id
await self._create_application_commands(application, self.http)
pass