from discord.ext import commands async def setup(bot: commands.Bot): await bot.add_cog(Admin(bot)) class Admin(commands.Cog): """Administrative functionality.""" def __init__(self, bot: commands.Bot): self.bot = bot @commands.command( name="gsync", description="Sync commands globally", brief="Synchronise commands with all Discord guilds", help="Update the bot commands for all Discord guilds" ) async def gsync(self, ctx: commands.Context): print(self.bot.tree.get_commands()) print(self.bot.tree.fetch_commands()) guild_count = 0 for guild in self.bot.guilds: fmt = await ctx.bot.tree.sync(guild=guild) guild_count += 1 await ctx.send(content=f"Synced tree of {len(fmt)} commands to {guild_count}/{len(self.bot.guilds)} guilds", ephemeral=True) @commands.command( name="sync", description="Sync commands", brief="Synchronise commands with Discord", help="Update the bot commands" ) async def sync(self, ctx: commands.Context): print(self.bot.tree.get_commands()) print(self.bot.tree.fetch_commands()) ctx.bot.tree.copy_global_to(guild=ctx.guild) synced = await ctx.bot.tree.sync(guild=ctx.guild) await ctx.send(content=f"Synced {len(synced)} commands to the current guild", ephemeral=True)