-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathmain.py
76 lines (57 loc) · 2.03 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
import os
import re
import asyncio
from itertools import cycle
import discord
from discord.ext import commands, tasks
from dotenv import load_dotenv
# to use repl+uptime monitor
# from utils.bot_uptime import start_server
# client = commands.Bot(command_prefix=['q', 'Q'], help_command=None)
client = commands.AutoShardedBot(shard_count=5, command_prefix=[
'q', 'Q'], help_command=None)
load_dotenv()
TOKEN = os.getenv('DISCORD_TOKEN')
with open("data/status_quotes.txt", "r") as file:
quotes = cycle(file.readlines())
@tasks.loop(seconds=1)
async def bot_status():
"""
An activity status which cycles through the
HP quotes every 15s
"""
await client.wait_until_ready()
await client.change_presence(
activity=discord.Activity(
type=discord.ActivityType.listening,
name=(next(quotes)).strip()
)
)
await asyncio.sleep(15)
# Comment out this function during development to see the
# traceback of all the errors
@client.event
async def on_command_error(ctx, error):
""" Catches command errors like cooldown, timeout etc """
# if cooldown error
if isinstance(error, discord.ext.commands.errors.CommandOnCooldown):
# Get the current timeout from the error message
timeout = (re.search(r"\d+\b", str(error))).group(0)
embed = discord.Embed(
description=str(error) +
f"\nThis message will self-destruct in {error.retry_after:.2f}s. \
You will be able to use the bot again when this message is deleted."
).set_footer(text=ctx.message.author)
message = await ctx.send(embed=embed)
await asyncio.sleep(int(timeout))
await message.delete()
else:
print(error)
bot_status.start()
# start_server()
client.load_extension("exts.cogs.book_search")
client.load_extension("exts.cogs.dictionary_search")
client.load_extension("exts.cogs.dictionary_index")
client.load_extension("exts.cogs.help")
client.load_extension("exts.cogs.settings")
client.run(TOKEN)