| 1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556 |
- from discord.ext import commands
- import discord
- 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)
- @commands.command(
- name="testsync",
- description="Sync commands",
- brief="Synchronise commands with Discord",
- help="Update the bot commands"
- )
- async def testsync(self, ctx: commands.Context):
- guild = discord.Object(id=962355492850638939)
- ctx.bot.tree.copy_global_to(guild=guild)
- synced = await ctx.bot.tree.sync(guild=guild)
- await ctx.send(content=f"Synced {len(synced)} commands to the test guild", ephemeral=True)
|