sync commands on startup

This commit is contained in:
JelNiSlaw 2023-06-19 14:08:49 +02:00
parent f963e701ab
commit 4737a47ebe
No known key found for this signature in database
GPG key ID: EA41571A0A88E97E
2 changed files with 2 additions and 23 deletions

View file

@ -20,6 +20,7 @@ class Wulkabot(commands.Bot):
async def setup_hook(self) -> None:
self.http_client = aiohttp.ClientSession()
await self.load_extensions(cogs)
await self.tree.sync()
async def on_connect(self) -> None:
print(f"Connected as {self.user}")
@ -42,7 +43,7 @@ class Wulkabot(commands.Bot):
return name.rsplit(".", maxsplit=1)[-1]
extensions = set()
for package in pkgutil.walk_packages(module.__path__, module.__name__ + "."):
for package in pkgutil.walk_packages(module.__path__, f"{module.__name__}."):
if package.ispkg or unqualify(package.name).startswith("_"):
continue
extensions.add(package.name)

View file

@ -1,22 +0,0 @@
from discord.ext import commands
from .. import bot
class Development(commands.Cog):
def __init__(self, bot: bot.Wulkabot) -> None:
super().__init__()
self.bot = bot
@commands.command()
@commands.has_role("Maintainer")
async def sync(self, ctx: commands.Context):
"""Synchronizuje komendy bota"""
commands = await self.bot.tree.sync()
commands_str = ", ".join(c.name for c in commands)
await ctx.reply(f"Zsynchronizowano **{len(commands)}** komend\n{commands_str}")
async def setup(bot: bot.Wulkabot):
await bot.add_cog(Development(bot))