-
Notifications
You must be signed in to change notification settings - Fork 37
/
main.py
70 lines (51 loc) · 2.17 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
import configparser
import aiohttp
import discord
from discord.ext import commands, tasks
from hijri_calendar.hijri_calendar import HijriCalendar
config = configparser.ConfigParser()
config.read('config.ini')
token = config['IslamBot']['token']
description = "A Discord bot with Islamic utilities. View Qur'an, hadith, prayer times and more."
intents = discord.Intents(messages=True, guilds=True)
@tasks.loop(hours=1)
async def update_presence():
hijri = HijriCalendar.get_current_hijri()
game = discord.Game(f"/help | {hijri}")
await bot.change_presence(activity=game)
@update_presence.before_loop
async def before_presence_update():
await bot.wait_until_ready()
class IslamBot(commands.AutoShardedBot):
def __init__(self) -> None:
super().__init__(command_prefix='-', description=description, case_insensitive=True, intents=intents)
self.initial_extensions = [
"quran.quran",
"quran.mushaf",
"quran.morphology",
"hijri_calendar.hijri_calendar",
"salaah.salaah_times",
"dua.dua",
"hadith.hadith",
"hadith.transmitter_biographies",
"tafsir.arabic_tafsir",
"tafsir.tafsir",
"miscellaneous.reload",
"miscellaneous.help",
"miscellaneous.TopGG" # Remove if using the bot locally
]
async def setup_hook(self):
self.session = aiohttp.ClientSession()
for ext in self.initial_extensions:
await self.load_extension(ext)
async def on_ready(self):
print(f'Logged in as {bot.user.name} ({bot.user.id}) on {len(bot.guilds)} servers')
# Sync commands globally
await bot.tree.sync(guild=None)
# If you are using the bot locally, uncomment the below and comment out the statement above so that commands
# only sync to your server. Global syncs are slow to propagate and are strictly rate-limited.
# await bot.tree.sync(guild=discord.Object(308241121165967362))
# Starting this in the setup hook causes a deadlock as before_presence_update calls wait_until_ready()
update_presence.start()
bot = IslamBot()
bot.run(token)