1
0

admin.py 1.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940
  1. from discord.ext import commands
  2. async def setup(bot: commands.Bot):
  3. await bot.add_cog(Admin(bot))
  4. class Admin(commands.Cog):
  5. """Administrative functionality."""
  6. def __init__(self, bot: commands.Bot):
  7. self.bot = bot
  8. @commands.command(
  9. name="gsync",
  10. description="Sync commands globally",
  11. brief="Synchronise commands with all Discord guilds",
  12. help="Update the bot commands for all Discord guilds"
  13. )
  14. async def gsync(self, ctx: commands.Context):
  15. print(self.bot.tree.get_commands())
  16. print(self.bot.tree.fetch_commands())
  17. guild_count = 0
  18. for guild in self.bot.guilds:
  19. fmt = await ctx.bot.tree.sync(guild=guild)
  20. guild_count += 1
  21. await ctx.send(content=f"Synced tree of {len(fmt)} commands to {guild_count}/{len(self.bot.guilds)} guilds", ephemeral=True)
  22. @commands.command(
  23. name="sync",
  24. description="Sync commands",
  25. brief="Synchronise commands with Discord",
  26. help="Update the bot commands"
  27. )
  28. async def sync(self, ctx: commands.Context):
  29. print(self.bot.tree.get_commands())
  30. print(self.bot.tree.fetch_commands())
  31. ctx.bot.tree.copy_global_to(guild=ctx.guild)
  32. synced = await ctx.bot.tree.sync(guild=ctx.guild)
  33. await ctx.send(content=f"Synced {len(synced)} commands to the current guild", ephemeral=True)