-
Notifications
You must be signed in to change notification settings - Fork 4
/
main.py
66 lines (50 loc) · 1.46 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
# Imports
import discord
import pymongo
import os
import asyncio
from helper import *
from discord.ext import commands, tasks
# Load environmental variables
try:
exec(open('variable.py').read())
except:
print('shit does not work, abort mission')
# Connect to mongodb database
dbclient = pymongo.MongoClient(os.environ.get('dbconn'))
db = dbclient['DaedBot']
guildcol = db['prefix']
queuecol = db['queue']
playlistcol = db['playlist']
blacklist_admin = db['adminblacklist']
intents=discord.Intents.all()
# Load custom prefixes
def get_prefix(client, message):
extras = guildcol.find_one({'guild_id': message.guild.id})
prefixes = extras['prefixes']
return commands.when_mentioned_or(*prefixes)(client, message)
def blacklist_check():
def predicate(ctx):
author_id = ctx.author.id
if blacklist_admin.find_one({'user_id': author_id}):
return False
return True
return commands.check(predicate)
# Start the bot
client = commands.Bot(
command_prefix=get_prefix,
owner_id=int(os.environ.get('owner')),
intents=intents,
)
# Automatically restarts the bot
@tasks.loop(hours=12, reconnect=True)
async def bot_restart():
os._exit(0)
# Remove default help command
client.remove_command('help')
# Load up cogs
for filename in os.listdir('./cogs'):
if filename.endswith('.py'):
client.load_extension(f'cogs.{filename[:-3]}')
# Run the bot
client.run(os.environ.get('DISCORD_TOKEN'), reconnect=True)