2022-09-13 14:00:27 +01:00
|
|
|
import discord
|
|
|
|
from discord.ext import commands
|
|
|
|
import config
|
2022-10-12 17:40:02 +01:00
|
|
|
from utils import registry, console
|
2022-09-13 14:00:27 +01:00
|
|
|
|
|
|
|
|
|
|
|
bot = commands.Bot(
|
2022-10-06 09:25:39 +01:00
|
|
|
commands.when_mentioned_or("h!"),
|
|
|
|
debug_guilds=config.guilds,
|
|
|
|
allowed_mentions=discord.AllowedMentions.none(),
|
|
|
|
intents=discord.Intents.default() + discord.Intents.members
|
2022-09-13 14:00:27 +01:00
|
|
|
)
|
2022-10-12 17:40:02 +01:00
|
|
|
|
2022-10-14 21:27:37 +01:00
|
|
|
extensions = [
|
|
|
|
"jishaku",
|
|
|
|
"cogs.verify",
|
|
|
|
"cogs.mod",
|
|
|
|
"cogs.events",
|
|
|
|
"cogs.assignments",
|
|
|
|
"cogs.timetable"
|
|
|
|
]
|
|
|
|
for ext in extensions:
|
2022-10-12 17:40:02 +01:00
|
|
|
bot.load_extension(ext)
|
|
|
|
console.log(f"Loaded extension [green]{ext}")
|
2022-09-13 20:50:02 +01:00
|
|
|
bot.loop.run_until_complete(registry.create_all())
|
2022-09-13 14:00:27 +01:00
|
|
|
|
|
|
|
|
2022-10-11 14:31:23 +01:00
|
|
|
@bot.listen()
|
2022-10-09 19:36:21 +01:00
|
|
|
async def on_connect():
|
2022-10-12 17:40:02 +01:00
|
|
|
console.log("[green]Connected to discord!")
|
2022-10-09 19:36:21 +01:00
|
|
|
|
|
|
|
|
2022-10-15 15:30:27 +01:00
|
|
|
@bot.listen("on_application_command_error")
|
|
|
|
async def on_application_command_error(ctx: discord.ApplicationContext, error: Exception):
|
|
|
|
await ctx.respond("Application Command Error: `%r`" % error)
|
2022-10-24 11:50:27 +01:00
|
|
|
raise error
|
2022-10-15 15:30:27 +01:00
|
|
|
|
|
|
|
|
2022-10-15 15:31:21 +01:00
|
|
|
@bot.listen("on_command_error")
|
2022-10-30 16:05:54 +00:00
|
|
|
async def on_command_error(ctx: commands.Context, error: Exception):
|
|
|
|
if isinstance(error, commands.CommandNotFound):
|
|
|
|
return
|
|
|
|
await ctx.reply("Command Error: `%r`" % error)
|
2022-10-24 11:50:27 +01:00
|
|
|
raise error
|
2022-10-15 15:31:21 +01:00
|
|
|
|
|
|
|
|
2022-10-11 14:31:23 +01:00
|
|
|
@bot.event
|
2022-09-13 14:00:27 +01:00
|
|
|
async def on_ready():
|
2022-10-12 17:40:02 +01:00
|
|
|
console.log("Logged in as", bot.user)
|
2022-09-13 14:00:27 +01:00
|
|
|
|
|
|
|
|
|
|
|
@bot.slash_command()
|
|
|
|
async def ping(ctx: discord.ApplicationContext):
|
2022-10-12 17:40:02 +01:00
|
|
|
# noinspection SpellCheckingInspection
|
2022-09-13 14:00:27 +01:00
|
|
|
"""Checks the bot's response time"""
|
|
|
|
gateway = round(ctx.bot.latency * 1000, 2)
|
2022-09-13 21:27:14 +01:00
|
|
|
return await ctx.respond(f"\N{white heavy check mark} Pong! `{gateway}ms`.")
|
2022-09-13 14:00:27 +01:00
|
|
|
|
|
|
|
|
2022-10-09 19:27:02 +01:00
|
|
|
if __name__ == "__main__":
|
2022-10-09 19:36:21 +01:00
|
|
|
print("Starting...")
|
2022-10-09 19:27:02 +01:00
|
|
|
bot.run(config.token)
|