-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathBot_Main.py
61 lines (47 loc) · 1.91 KB
/
Bot_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
# import logging
from concurrent.futures import ProcessPoolExecutor
from discord import Activity
from discord import ActivityType
from discord import Intents
from discord.ext.commands import Bot
from discord.ext.commands import DefaultHelpCommand
from util import config
async def prefix_func(_bot, msg):
prefs = [f'<@{_bot.user.id}> ', f'<@!{_bot.user.id}> ']
if msg.guild and hasattr(_bot, 'db'):
pref = await _bot.db.get_prefix(msg.guild.id)
prefs.append(pref or config.prefix)
else:
prefs.append(config.prefix)
return prefs
if __name__ == '__main__':
game = Activity(type=ActivityType.playing, name=config.activity)
intents = Intents.all()
bot = Bot(command_prefix=prefix_func,
intents=intents,
owner_id=config.owner_id,
activity=game,
help_command=DefaultHelpCommand(command_attrs={'aliases': ['halp']}))
@bot.event
async def on_ready():
print('Logged in as')
print(bot.user.name)
print(bot.user.id)
print('------')
if 'cogs.logs' not in bot.extensions:
print('Logs cog failed to load!')
chan = bot.get_channel(config.bot_log_id)
await chan.send("Help me <@{}>! I failed to load my logging cog!".format(config.owner_id))
# logger = logging.getLogger('discord')
# logger.setLevel(logging.WARNING)
# handler = logging.FileHandler(filename=config.logfile, encoding='utf-8', mode='w')
# handler.setFormatter(logging.Formatter('%(asctime)s:%(levelname)s:%(name)s: %(message)s'))
# logger.addHandler(handler)
for extension in config.cogs_core:
try:
bot.load_extension(extension)
except Exception as e:
print('Failed to load extension {}.'.format(extension))
print(e)
bot.process_pool = ProcessPoolExecutor(max_workers=config.max_process_workers)
bot.run(config.token)