aboutsummaryrefslogtreecommitdiff
path: root/code/cogs/tree_sync.py
blob: b84766e7be883dd16f4c7809d195c4ec929cee82 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
from discord.ext import commands
from discord import Object


class TreeSync(commands.Cog):
    def __init__(self, bot):
        self.bot = bot

    @commands.command()
    @commands.dm_only()
    @commands.is_owner()
    async def sync(
        self, ctx: commands.Context, *, guild: Object = None
    ) -> None:
        if not guild or guild == None:
            await self.bot.tree.sync()
            await ctx.author.send("Synced commands globally")
            return

        elif guild != None:
            self.bot.tree.copy_global_to(guild=guild)
            await self.bot.tree.sync(guild=guild)

        await ctx.author.send(f"Synced the tree to 1 test guild.")

    @sync.error
    async def error_sync(self, ctx, error):
        if isinstance(error, commands.errors.PrivateMessageOnly):
            pass
        else:
            await ctx.author.send("That is not a valid guild ID")


async def setup(bot):
    await bot.add_cog(TreeSync(bot))