77"""
88
99import json
10+ import os
11+ import sys
1012
1113import discord
14+ from discord import app_commands
1215from discord .ext import commands
1316from discord .ext .commands import Context
1417
1518from helpers import checks
1619from helpers import db_manager
1720
21+ if not os .path .isfile ("config.json" ):
22+ sys .exit ("'config.json' not found! Please add it and try again." )
23+ else :
24+ with open ("config.json" ) as file :
25+ config = json .load (file )
1826
1927class Owner (commands .Cog , name = "owner" ):
2028 def __init__ (self , bot ):
2129 self .bot = bot
2230
31+ DEV_GUILD = discord .Object (id = config ["dev_guild_id" ])
32+
33+ @commands .hybrid_command (
34+ name = "sync" ,
35+ description = "Synchonizes the slash commands." ,
36+ )
37+ @checks .is_owner ()
38+ @app_commands .guilds (DEV_GUILD )
39+ async def sync (self , context : Context ) -> None :
40+ """
41+ Synchonizes the slash commands.
42+
43+ :param context: The hybrid command context.
44+ """
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+
52+ @commands .hybrid_command (
53+ name = "unsync" ,
54+ description = "Unsynchonizes the slash commands." ,
55+ )
56+ @checks .is_owner ()
57+ @app_commands .guilds (DEV_GUILD )
58+ async def unsync (self , context : Context ) -> None :
59+ """
60+ Unsynchonizes the slash commands.
61+
62+ :param context: The hybrid command context.
63+ """
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 )
71+
2372 @commands .hybrid_command (
2473 name = "load" ,
2574 description = "Load a cog" ,
2675 )
76+ @app_commands .describe (cog = "The name of the cog to load" )
2777 @checks .is_owner ()
2878 async def load (self , context : Context , cog : str ) -> None :
2979 """
3080 The bot will load the given cog.
81+
3182 :param context: The hybrid command context.
32- :param cog: The cog to be loaded .
83+ :param cog: The name of the cog to load .
3384 """
3485 try :
3586 await self .bot .load_extension (f"cogs.{ cog } " )
3687 except Exception as e :
37- embed = discord .Embed (title = "Error!" , description = f"Could not load the `{ cog } ` cog." )
38- await context .send (embed = embed ); return
39- embed = discord .Embed (title = "Load" , description = f"Successfully loaded the `{ cog } ` cog." )
88+ embed = discord .Embed (
89+ title = "Error!" ,
90+ description = f"Could not load the `{ cog } ` cog."
91+ )
92+ await context .send (embed = embed )
93+ return
94+ embed = discord .Embed (
95+ title = "Load" ,
96+ description = f"Successfully loaded the `{ cog } ` cog."
97+ )
4098 await context .send (embed = embed )
4199
42-
43100 @commands .hybrid_command (
44101 name = "unload" ,
45102 description = "Unloads a cog." ,
46103 )
104+ @app_commands .describe (cog = "The name of the cog to unload" )
47105 @checks .is_owner ()
48106 async def unload (self , context : Context , cog : str ) -> None :
49107 """
50108 The bot will unload the given cog.
109+
51110 :param context: The hybrid command context.
52- :param cog: The cog to be unloaded .
111+ :param cog: The name of the cog to unload .
53112 """
54113 try :
55114 await self .bot .unload_extension (f"cogs.{ cog } " )
56115 except Exception as e :
57- embed = discord .Embed (title = "Error!" , description = f"Could not unload the `{ cog } ` cog." )
58- await context .send (embed = embed ); return
59- embed = discord .Embed (title = "Unload" , description = f"Successfully loaded the `{ cog } ` cog." )
116+ embed = discord .Embed (
117+ title = "Error!" ,
118+ description = f"Could not unload the `{ cog } ` cog."
119+ )
120+ await context .send (embed = embed )
121+ return
122+ embed = discord .Embed (
123+ title = "Unload" ,
124+ description = f"Successfully loaded the `{ cog } ` cog."
125+ )
60126 await context .send (embed = embed )
61127
62128 @commands .hybrid_command (
63129 name = "reload" ,
64130 description = "Reloads a cog." ,
65131 )
132+ @app_commands .describe (cog = "The name of the cog to reload" )
66133 @checks .is_owner ()
67134 async def reload (self , context : Context , cog : str ) -> None :
68135 """
69136 The bot will reload the given cog.
137+
70138 :param context: The hybrid command context.
71- :param cog: The cog to be reloaded .
139+ :param cog: The name of the cog to reload .
72140 """
73141 try :
74142 await self .bot .reload_extension (f"cogs.{ cog } " )
75143 except Exception as e :
76- embed = discord .Embed (title = "Error!" , description = f"Could not reload the `{ cog } ` cog." )
77- await context .send (embed = embed ); return
78- embed = discord .Embed (title = "Reload" , description = f"Successfully reloaded the `{ cog } ` cog." )
144+ embed = discord .Embed (
145+ title = "Error!" ,
146+ description = f"Could not reload the `{ cog } ` cog."
147+ )
148+ await context .send (embed = embed )
149+ return
150+ embed = discord .Embed (
151+ title = "Reload" ,
152+ description = f"Successfully reloaded the `{ cog } ` cog."
153+ )
79154 await context .send (embed = embed )
80155
81156 @commands .hybrid_command (
@@ -100,6 +175,7 @@ async def shutdown(self, context: Context) -> None:
100175 name = "say" ,
101176 description = "The bot will say anything you want." ,
102177 )
178+ @app_commands .describe (message = "The message that should be repeated by the bot" )
103179 @checks .is_owner ()
104180 async def say (self , context : Context , message : str ) -> None :
105181 """
@@ -114,6 +190,7 @@ async def say(self, context: Context, message: str) -> None:
114190 name = "embed" ,
115191 description = "The bot will say anything you want, but within embeds." ,
116192 )
193+ @app_commands .describe (message = "The message that should be repeated by the bot" )
117194 @checks .is_owner ()
118195 async def embed (self , context : Context , message : str ) -> None :
119196 """
@@ -146,6 +223,7 @@ async def blacklist(self, context: Context) -> None:
146223 name = "add" ,
147224 description = "Lets you add a user from not being able to use the bot." ,
148225 )
226+ @app_commands .describe (user = "The user that should be added to the blacklist" )
149227 @checks .is_owner ()
150228 async def blacklist_add (self , context : Context , user : discord .User ) -> None :
151229 """
@@ -161,7 +239,8 @@ async def blacklist_add(self, context: Context, user: discord.User) -> None:
161239 description = f"**{ user .name } ** is not in the blacklist." ,
162240 color = 0xE02B2B
163241 )
164- return await context .send (embed = embed )
242+ await context .send (embed = embed )
243+ return
165244 total = db_manager .add_user_to_blacklist (user_id )
166245 embed = discord .Embed (
167246 title = "User Blacklisted" ,
@@ -178,8 +257,9 @@ async def blacklist_add(self, context: Context, user: discord.User) -> None:
178257 name = "remove" ,
179258 description = "Lets you remove a user from not being able to use the bot." ,
180259 )
260+ @app_commands .describe (user = "The user that should be removed from the blacklist." )
181261 @checks .is_owner ()
182- async def blacklist_remove (self , context : Context , user : discord .User ):
262+ async def blacklist_remove (self , context : Context , user : discord .User ) -> None :
183263 """
184264 Lets you remove a user from not being able to use the bot.
185265
@@ -193,7 +273,8 @@ async def blacklist_remove(self, context: Context, user: discord.User):
193273 description = f"**{ user .name } ** is already in the blacklist." ,
194274 color = 0xE02B2B
195275 )
196- return await context .send (embed = embed )
276+ await context .send (embed = embed )
277+ return
197278 total = db_manager .remove_user_from_blacklist (user_id )
198279 embed = discord .Embed (
199280 title = "User removed from blacklist" ,
0 commit comments