-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.py
128 lines (95 loc) · 3.81 KB
/
main.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
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
import discord
from discord.ext import commands
import logging
import os
logging.basicConfig(level=logging.INFO,
format='%(asctime)s %(levelname)s » %(message)s')
intents = discord.Intents.all()
class MyBot(commands.Bot):
async def setup_hook(self):
for filename in os.listdir('./cogs'):
if filename.endswith('.py'):
await bot.load_extension(f"cogs.{filename[:-3]}")
logging.info(f"{filename} Loaded!")
else:
logging.error(f"Impossible Loading {filename}.")
print('Nobelium Bot setup completed')
bot = MyBot(command_prefix=';', intents=intents, activity=discord.Activity(type=discord.ActivityType.playing, name='Nobelium Bot'))
@bot.event
async def on_ready():
print("Nobelium Bot Running")
@bot.event
async def on_connect():
print("Nobelium Connected to Discord")
@bot.command(
name='unload',
description='Unloads cog from the bot.',
usage='£unload (Cog)',
brief='Unload cog',
aliases=["ul"]
)
@commands.has_role(859467091639009350)
async def unload(ctx, extension = None):
if extension != None:
await bot.unload_extension(f'cogs.{extension}')
embed = discord.Embed(description=f":no_entry: Unloaded `cogs.{extension}`", color=discord.Color.dark_green())
await ctx.reply(embed=embed)
else:
for filename in os.listdir('./cogs'):
if filename.endswith('.py'):
await bot.unload_extension(f'cogs.{filename[:-3]}')
embed = discord.Embed(description=f":ballot_box_with_check: Unloaded all cogs", color=discord.Color.dark_green())
await ctx.reply(embed=embed)
@bot.command(
name='reload',
description='Reload cog from the bot.',
usage='£reload (Cog)',
brief='Reload cog',
aliases=["rl"]
)
#@commands.has_role(859467091639009350)
async def reload(ctx, extension = None):
if extension != None:
await bot.reload_extension(f'cogs.{extension}')
embed = discord.Embed(description=f"🔄 Reloaded `cogs.{extension}`", color=discord.Color.dark_green())
await ctx.reply(embed=embed)
else:
for filename in os.listdir('./cogs'):
if filename.endswith('.py'):
await bot.reload_extension(f'cogs.{filename[:-3]}')
embed = discord.Embed(description=f"🔄 Reloaded all cogs", color=discord.Color.dark_green())
await ctx.reply(embed=embed)
@bot.command(
name='load',
description='Loads cog from the bot.',
usage='£load (Cog)',
brief='Load cog',
aliases=["ld"]
)
@commands.has_role(859467091639009350)
async def load(ctx, extension = None):
if extension != None:
await bot.load_extension(f'cogs.{extension}')
embed = discord.Embed(description=f":ballot_box_with_check: Loaded `cogs.{extension}`", color=discord.Color.dark_green())
await ctx.reply(embed=embed)
else:
for filename in os.listdir('./cogs'):
if filename.endswith('.py'):
await bot.load_extension(f'cogs.{filename[:-3]}')
embed = discord.Embed(description=f":ballot_box_with_check: Loaded all cogs", color=discord.Color.dark_green())
await ctx.reply(embed=embed)
@unload.error
@load.error
#@reload.error
async def handler(ctx, error):
if isinstance(error, commands.MissingRole):
embed = discord.Embed(
description=":x: You don't have the permission to use this command.", color=discord.Color.red())
await ctx.reply(embed=embed)
elif isinstance(error, commands.ExtensionAlreadyLoaded):
embed = discord.Embed(
description=":x: Extension already loaded.", color=discord.Color.red())
await ctx.reply(embed=embed)
else:
print(error)
bot.run(os.getenv('NOBELIUM_TOK'))