forked from nextcord/previous
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.py
74 lines (59 loc) · 2.09 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
import os
from os import environ as env
from re import compile
import aiohttp
import nextcord
from nextcord import Intents
from nextcord.ext import commands
from nextcord.ext.commands import errors
bot = commands.Bot("=", intents=Intents(messages=True, guilds=True, members=True))
bot.load_extension("jishaku")
issue_regex = compile(r"##(\d+)")
discord_regex = compile(r"#!(\d+)")
@bot.event
async def on_command_error(ctx, error):
if isinstance(error, errors.CommandNotFound):
return
elif isinstance(error, errors.TooManyArguments):
await ctx.send("You are giving too many arguments!")
return
elif isinstance(error, errors.BadArgument):
await ctx.send(
"The library ran into an error attempting to parse your argument."
)
return
elif isinstance(error, errors.MissingRequiredArgument):
await ctx.send("You're missing a required argument.")
# kinda annoying and useless error.
elif isinstance(error, nextcord.NotFound) and "Unknown interaction" in str(error):
return
else:
await ctx.send(
f"This command raised an exception: `{type(error)}:{str(error)}`"
)
@bot.listen()
async def on_message(message):
if result := issue_regex.search(message.content):
issue_id = result.groups()[0]
await message.channel.send(
f"https://github.com/nextcord/nextcord/issues/{issue_id}"
)
if result := discord_regex.search(message.content):
issue_id = result.groups()[0]
await message.channel.send(
f"https://github.com/rapptz/discord.py/issues/{issue_id}"
)
@bot.command()
async def todo(ctx):
await ctx.send(
"https://github.com/nextcord/nextcord/projects/1 and going through all the issues"
)
for filename in os.listdir("./cogs"):
if filename.endswith(".py"):
bot.load_extension(f"cogs.{filename[:-3]}")
elif os.path.isfile(filename):
print(f"Unable to load {filename[:-3]}")
async def startup():
bot.session = aiohttp.ClientSession()
bot.loop.create_task(startup())
bot.run(env["TOKEN"])