|
14 | 14 | from discord import app_commands |
15 | 15 | from discord.ext import commands |
16 | 16 | from discord.ext.commands import Context |
17 | | - |
18 | | -from helpers import checks |
19 | | -from helpers import db_manager |
| 17 | +from helpers import checks, db_manager |
20 | 18 |
|
21 | 19 | if not os.path.isfile("config.json"): |
22 | 20 | sys.exit("'config.json' not found! Please add it and try again.") |
23 | 21 | else: |
24 | 22 | with open("config.json") as file: |
25 | 23 | config = json.load(file) |
26 | 24 |
|
| 25 | + |
27 | 26 | class Owner(commands.Cog, name="owner"): |
28 | 27 | def __init__(self, bot): |
29 | 28 | self.bot = bot |
30 | | - |
31 | | - DEV_GUILD = discord.Object(id=config["dev_guild_id"]) |
32 | 29 |
|
33 | | - @commands.hybrid_command( |
| 30 | + @commands.command( |
34 | 31 | name="sync", |
35 | 32 | description="Synchonizes the slash commands.", |
36 | 33 | ) |
| 34 | + @app_commands.describe(scope="The scope of the sync. Can be `global` or `guild`") |
37 | 35 | @checks.is_owner() |
38 | | - @app_commands.guilds(DEV_GUILD) |
39 | | - async def sync(self, context: Context) -> None: |
| 36 | + async def sync(self, context: Context, scope: str) -> None: |
40 | 37 | """ |
41 | 38 | Synchonizes the slash commands. |
42 | 39 |
|
43 | | - :param context: The hybrid command context. |
| 40 | + :param context: The command context. |
| 41 | + :param scope: The scope of the sync. Can be `global` or `guild`. |
44 | 42 | """ |
45 | | - await self.bot.tree.sync() |
46 | | - embed = discord.Embed( |
47 | | - title="Slash Commands Sync", |
48 | | - description="Slash commands have been synchronized.", |
49 | | - ) |
50 | | - await context.send(embed=embed) |
51 | 43 |
|
52 | | - @commands.hybrid_command( |
| 44 | + if scope == "global": |
| 45 | + await context.bot.tree.sync() |
| 46 | + embed = discord.Embed( |
| 47 | + title="Slash Commands Sync", |
| 48 | + description="Slash commands have been globally synchronized.", |
| 49 | + color=0x9C84EF |
| 50 | + ) |
| 51 | + await context.send(embed=embed) |
| 52 | + elif scope == "guild": |
| 53 | + context.bot.tree.copy_global_to(guild=context.guild) |
| 54 | + await context.bot.tree.sync(guild=context.guild) |
| 55 | + embed = discord.Embed( |
| 56 | + title="Slash Commands Sync", |
| 57 | + description="Slash commands have been synchronized in this guild.", |
| 58 | + color=0x9C84EF |
| 59 | + ) |
| 60 | + await context.send(embed=embed) |
| 61 | + else: |
| 62 | + embed = discord.Embed( |
| 63 | + title="Invalid Scope", |
| 64 | + description="The scope must be `global` or `guild`.", |
| 65 | + color=0xE02B2B |
| 66 | + ) |
| 67 | + await context.send(embed=embed) |
| 68 | + |
| 69 | + @commands.command( |
53 | 70 | name="unsync", |
54 | 71 | description="Unsynchonizes the slash commands.", |
55 | 72 | ) |
| 73 | + @app_commands.describe(scope="The scope of the sync. Can be `global`, `current_guild` or `guild`") |
56 | 74 | @checks.is_owner() |
57 | | - @app_commands.guilds(DEV_GUILD) |
58 | | - async def unsync(self, context: Context) -> None: |
| 75 | + async def unsync(self, context: Context, scope: str) -> None: |
59 | 76 | """ |
60 | 77 | Unsynchonizes the slash commands. |
61 | 78 |
|
62 | | - :param context: The hybrid command context. |
| 79 | + :param context: The command context. |
| 80 | + :param scope: The scope of the sync. Can be `global`, `current_guild` or `guild`. |
63 | 81 | """ |
64 | | - self.bot.tree.clear_commands(guild=None) |
65 | | - await self.bot.tree.sync() |
66 | | - embed = discord.Embed( |
67 | | - title="Slash Commands Unsync", |
68 | | - description="Slash commands have been unsynchronized.", |
69 | | - ) |
70 | | - await context.send(embed=embed) |
| 82 | + |
| 83 | + if scope == "global": |
| 84 | + context.bot.tree.clear_commands(guild=None) |
| 85 | + await context.bot.tree.sync() |
| 86 | + embed = discord.Embed( |
| 87 | + title="Slash Commands Unsync", |
| 88 | + description="Slash commands have been globally unsynchronized.", |
| 89 | + color=0x9C84EF |
| 90 | + ) |
| 91 | + await context.send(embed=embed) |
| 92 | + elif scope == "guild": |
| 93 | + context.bot.tree.clear_commands(guild=context.guild) |
| 94 | + await context.bot.tree.sync(guild=context.guild) |
| 95 | + embed = discord.Embed( |
| 96 | + title="Slash Commands Unsync", |
| 97 | + description="Slash commands have been unsynchronized in this guild.", |
| 98 | + color=0x9C84EF |
| 99 | + ) |
| 100 | + await context.send(embed=embed) |
| 101 | + else: |
| 102 | + embed = discord.Embed( |
| 103 | + title="Invalid Scope", |
| 104 | + description="The scope must be `global` or `guild`.", |
| 105 | + color=0xE02B2B |
| 106 | + ) |
| 107 | + await context.send(embed=embed) |
71 | 108 |
|
72 | 109 | @commands.hybrid_command( |
73 | 110 | name="load", |
@@ -151,7 +188,7 @@ async def reload(self, context: Context, cog: str) -> None: |
151 | 188 | title="Reload", |
152 | 189 | description=f"Successfully reloaded the `{cog}` cog." |
153 | 190 | ) |
154 | | - await context.send(embed=embed) |
| 191 | + await context.send(embed=embed) |
155 | 192 |
|
156 | 193 | @commands.hybrid_command( |
157 | 194 | name="shutdown", |
|
0 commit comments