-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathCogManager.py
90 lines (72 loc) · 2.57 KB
/
CogManager.py
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
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
'''
SETUP:
All you need to do is add a `cogs` folder and move all of your cog files there, thats it!
'''
def get_extensions(): # Gets extension list dynamically
extensions = []
for file in Path("cogs").glob("**/*.py"):
if "!" in file.name or "__" in file.name:
continue
extensions.append(str(file).replace("/", ".").replace(".py", ""))
return extensions
for ext in get_extensions(): #Loads every cog in your cog folder
client.load_extension(ext)
@client.group(aliases=['cog'])
@commands.is_owner()
async def cogs(ctx):
pass
@cogs.command()
@commands.is_owner()
async def unload(ctx, ext):
if "cogs." not in ext:
ext = f"cogs.{ext}"
if ext in get_extensions():
client.unload_extension(ext)
embed = discord.Embed(
title="Cogs - Unload", description=f"Unloaded cog: {ext}", color=0xd6b4e8)
await ctx.send(embed=embed)
else:
embed = discord.Embed(
title="Cogs Reloaded", description=f"Cog '{ext}' not found", color=0xd6b4e8)
await ctx.send(embed=embed)
@cogs.command()
@commands.is_owner()
async def load(ctx, ext):
if "cogs." not in ext:
ext = f"cogs.{ext}"
if ext in get_extensions():
client.load_extension(ext)
embed = discord.Embed(title="Cogs - Load",
description=f"Loaded cog: {ext}", color=0xd6b4e8)
await ctx.send(embed=embed)
else:
embed = discord.Embed(
title="Cogs - Load", description=f"Cog '{ext}' not found.", color=0xd6b4e8)
await ctx.send(embed=embed)
@cogs.command(aliases=['restart'])
@commands.is_owner()
async def reload(ctx, ext):
if ext == "all":
embed = discord.Embed(
title="Cogs - Reload", description="Reloaded all cogs", color=0xd6b4e8)
for extension in get_extensions():
client.reload_extension(extension)
await ctx.send(embed=embed)
return
if "cogs." not in ext:
ext = f"cogs.{ext}"
if ext in get_extensions():
client.reload_extension(ext)
embed = discord.Embed(
title="Cogs - Reload", description=f"Reloaded cog: {ext}", color=0xd6b4e8)
await ctx.send(embed=embed)
else:
embed = discord.Embed(
title="Cogs - Reload", description=f"Cog '{ext}' not found.", color=0xd6b4e8)
await ctx.send(embed=embed)
@cogs.command()
@commands.is_owner()
async def view(ctx):
msg = " ".join(get_extensions())
embed = discord.Embed(title="Cogs - View", description=msg, color=0xd6b4e8)
await ctx.send(embed=embed)