-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbot.py
111 lines (93 loc) · 4.26 KB
/
bot.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
# NCXBot "bot.py"
# Copyright (C) 2022 NinjaCheetah
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <https://www.gnu.org/licenses/>.
import asyncio
import discord
from discord.ext import commands
import json
with open('config.json', 'r') as f:
config = json.load(f)
TOKEN = config["TOKEN"]
# GUILD = config["GUILD"]
class Bot(commands.Bot):
def __init__(self, **kwargs) -> None:
super().__init__(**kwargs)
async def process_commands(self, message: discord.Message):
ctx = await self.get_context(message)
await self.invoke(ctx)
intents = discord.Intents.all()
bot = Bot(command_prefix='x!', activity=discord.Game(name="Programming | x!help", type=3), intents=intents)
bot.remove_command('help')
startup_extensions = ["cogs.fortunes", "cogs.help", "cogs.management", "cogs.misc", "cogs.software", "cogs.weblinks"]
@bot.event
async def on_command_error(ctx, error):
if isinstance(error, commands.MissingRequiredArgument):
await ctx.send(":x: You are missing a required argument!")
if isinstance(error, commands.CommandNotFound):
print("Command not found.")
if isinstance(error, commands.ExtensionError):
await ctx.send(":x: That extension could not be found!")
if isinstance(error, commands.ExtensionNotLoaded):
await ctx.send(":x: There was an error while loading that extension.")
if isinstance(error, commands.ExtensionFailed):
await ctx.send(":x: There was an error while loading that extension.")
if isinstance(error, commands.ExtensionNotFound):
await ctx.send(":x: That extension could not be found!")
@bot.command(name='load', help='Loads an extension.')
@commands.is_owner()
async def load(ctx, extension):
try:
await bot.load_extension(f'cogs.{extension}')
await ctx.send(":white_check_mark: Loaded `cogs."+extension+"`")
except Exception as e:
exc = '{}: {}'.format(type(e).__name__, e)
await ctx.send(":warning: Failed to load extension `{}`\n```\n{}\n```".format(extension, exc))
@bot.command(name='unload', help='Unloads an extension.')
@commands.is_owner()
async def unload(ctx, extension):
await bot.unload_extension(f'cogs.{extension}')
await ctx.send(":white_check_mark: Unloaded `cogs."+extension+"`")
@bot.command(name='reload', help='Reloads an extension.')
@commands.is_owner()
async def reload(ctx, extension):
try:
await bot.reload_extension(f'cogs.{extension}')
await ctx.send(":repeat: Reloaded `cogs."+extension+"`")
except Exception as e:
exc = '{}: {}'.format(type(e).__name__, e)
await ctx.send(":warning: Failed to reload extension `{}`\n```\n{}\n```".format(extension, exc))
@bot.command(name='reloadall', help='Reloads all extensions.')
@commands.is_owner()
async def reloadall(ctx):
for extension in startup_extensions:
try:
await bot.reload_extension(extension)
await ctx.send(":repeat: Reloaded `"+extension+"`")
except Exception as e:
exc = '{}: {}'.format(type(e).__name__, e)
await ctx.send(":warning: Failed to reload extension `{}`\n```\n{}\n```".format(extension, exc))
async def load_extensions():
await bot.load_extension('jishaku')
for extension in startup_extensions:
try:
await bot.load_extension(extension)
except Exception as e:
exc = '{}: {}'.format(type(e).__name__, e)
print('Failed to load extension {}\n{}'.format(extension, exc))
@bot.event
async def on_ready():
print("Ready!")
async def main():
async with bot:
await load_extensions()
await bot.start(TOKEN)
asyncio.run(main())