-
Notifications
You must be signed in to change notification settings - Fork 0
/
run.py
69 lines (51 loc) · 1.81 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
60
61
62
63
64
65
66
67
68
69
""" Entry point for python application. Run this file to start the bot. """
import sys
import discord
import logging
import models
logging.basicConfig(level=logging.INFO, filename='discord.log',
filemode='w', format='date+time:%(asctime)s | %(message)s')
models.load_dot_env()
DEBUG_GUILDS = models.get_env_safe(models.ENVs.DEBUG_GUILDS).split(',')
bot = discord.Bot(debug_guilds=DEBUG_GUILDS)
extensions = [
"test",
"roles",
]
@bot.event
async def on_ready():
print(f'\n{bot.user} is ready and online!')
print(f'Connected to {len(bot.guilds)} Guilds:')
print('\n'.join([f' - {guild} ({guild.id})' for guild in bot.guilds]))
logging.info(f'{bot.user} is ready and online!')
logging.info(f'Connected to {len(bot.guilds)} Guilds:')
for guild in bot.guilds:
logging.info(f'{guild}|{guild.id}')
@bot.slash_command(guild_ids=DEBUG_GUILDS)
async def refresh(ctx):
reload_extensions()
await ctx.respond("Refreshed extensions!")
def load_extensions():
for ext in extensions:
bot.load_extension(f'cogs.{ext}')
def unload_extensions():
for ext in extensions:
bot.unload_extension(f'cogs.{ext}')
def reload_extensions():
for ext in extensions:
bot.reload_extension(f'cogs.{ext}')
def main():
# Whether to deploy to testing bot or main bot (defaults to testing)
token = models.ENVs.DEBUG_TOKEN
if len(sys.argv) > 1 and sys.argv[1] == 'deploy':
token = models.ENVs.TOKEN
# Run Pycord Bot until keyboard interrupt
logging.info(f'Starting Pycord Bot...')
load_extensions()
bot.run(models.get_env_safe(token, accept_empty=False))
unload_extensions()
# Safely shut down connections and save data
print(f'\nShutting down...')
logging.info(f'Shutting down...')
if __name__ == '__main__':
main()