-
Notifications
You must be signed in to change notification settings - Fork 6
/
Copy pathbot.py
executable file
·88 lines (70 loc) · 2.65 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
# Main bot file
import os, time
import discord
import datetime
import json
from dotenv import load_dotenv
from discord.ext import commands
__version__ = '1.0.0'
load_dotenv()
TOKEN = os.getenv('DISCORD_TOKEN')
DEFAULT_PREFIX = '+'
description = "A Discord bot with Quran player and Islamic utilities."
cog_list = [#'topgg', 'events',
'reciters', 'audio', 'admin',
'general', 'quran', 'hadith', 'hijricalendar',
'prayertimes', 'quran-morphology', 'tafsir', 'tafsir-english', 'mushaf', 'dua', 'help']
intents = discord.Intents.default()
def get_prefix(bot, message):
if not message.guild:
return commands.when_mentioned_or(DEFAULT_PREFIX)(bot, message)
with open('prefixes.json', 'r') as file:
prefixes = json.load(file)
if str(message.guild.id) not in prefixes:
return commands.when_mentioned_or(DEFAULT_PREFIX)(bot, message)
prefix = prefixes[str(message.guild.id)]
return commands.when_mentioned_or(prefix)(bot, message)
bot = commands.AutoShardedBot(command_prefix=get_prefix, description=description, intents=intents)
@bot.event
async def on_ready():
for cog in cog_list:
cog = f'cogs.{cog}'
try:
await bot.load_extension(cog)
except Exception as e:
print(f'Couldn\'t load cog {cog}')
raise e
await bot.tree.sync()
print('------------------------')
print(f'Logged in as {bot.user.name} (ID: {bot.user.id}) on {len(bot.guilds)} servers')
print(f'Discord Version: {discord.__version__}')
print(f'Bot Version: {__version__}')
bot.AppInfo = await bot.application_info()
print(f'Owner: {bot.AppInfo.owner}')
print('------Bot is Ready------')
@bot.command()
@commands.is_owner()
async def reload(ctx, cog=None):
if cog == None:
try:
for item in cog_list:
bot.unload_extension(f'cogs.{item}')
bot.load_extension(f'cogs.{item}')
await ctx.send('All cogs got reloaded.')
print('----------\nAll cogs got reloaded.\n----------')
except Exception as e:
await ctx.send('Cogs can not be loaded!')
raise e
else:
try:
bot.unload_extension(f'cogs.{cog}')
bot.load_extension(f'cogs.{cog}')
await ctx.send(f'`{cog}` got reloaded.')
print(f'----------\n`{cog}` got reloaded.\n----------')
except Exception as e:
if cog in cog_list:
await ctx.send(f'`{cog}` can not be loaded! **Check the Log**')
else:
await ctx.send(f'`{cog}` is not a valid cog!')
raise e
bot.run(TOKEN)