-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathrun.py
59 lines (45 loc) · 1.5 KB
/
run.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
import asyncio
import discord
import logging
import os
from discord.ext import commands
# Discord BOT token
TOKEN = os.getenv('DISCORD_TOKEN')
# Plugins to be loaded
PLUGINS = os.getenv('PLUGINS') or 'bans'
class DGSABot(commands.Bot):
def __init__(self):
super().__init__(command_prefix=get_prefix,
description='DGSA Bot',
case_insensitive=True,
intents=discord.Intents.all())
self.synced = False
# Initialize the logger and i18n
logging.basicConfig(level=logging.INFO)
self.log = logging.getLogger(name='dgsabot')
async def setup_hook(self) -> None:
# Removes the default help command
bot.remove_command('help')
# Make sure to do this before loading the cogs
for plugin in PLUGINS.split(','):
await bot.load_extension('plugins.' + plugin.strip().lower())
def get_prefix(client, message):
prefixes = ['!']
# Allow users to @mention the bot instead of using a prefix
return commands.when_mentioned_or(*prefixes)(client, message)
# Create the Bot
bot = DGSABot()
@bot.event
async def on_ready() -> None:
if not bot.synced:
await bot.tree.sync()
bot.synced = True
bot.log.info(f'Logged in as {bot.user.name} - {bot.user.id}')
async def main():
async with bot:
await bot.start(TOKEN, reconnect=True)
if __name__ == '__main__':
try:
asyncio.run(main())
except KeyboardInterrupt:
exit(-1)