1
0
Fork 0
mirror of https://github.com/uhIgnacio/EmoteManager.git synced 2024-08-15 02:23:13 +00:00
EmoteManager/bot.py

56 lines
1.8 KiB
Python
Raw Normal View History

2018-07-30 03:48:58 +00:00
#!/usr/bin/env python3
# encoding: utf-8
2018-07-30 05:15:38 +00:00
import logging
2018-07-30 05:26:06 +00:00
import traceback
2018-07-30 05:15:38 +00:00
2018-07-30 03:48:58 +00:00
import discord
from discord.ext import commands
2018-07-30 05:15:38 +00:00
logging.basicConfig(level=logging.WARNING)
logger = logging.getLogger(__name__)
logger.setLevel(logging.INFO)
2018-07-30 03:48:58 +00:00
class Bot(commands.AutoShardedBot):
def __init__(self, **kwargs):
super().__init__(command_prefix=commands.when_mentioned, **kwargs)
with open('config.py') as f:
self.config = eval(f.read(), {})
for cog in self.config['cogs']:
self.load_extension(cog)
def run(self):
super().run(self.config['tokens'].pop('discord'))
2018-07-30 03:48:58 +00:00
async def on_ready(self):
2018-07-30 05:15:38 +00:00
logger.info('Logged on as {0} (ID: {0.id})'.format(self.user))
# https://github.com/Rapptz/RoboDanny/blob/ca75fae7de132e55270e53d89bc19dd2958c2ae0/bot.py#L77-L85
async def on_command_error(self, context, error):
if isinstance(error, commands.NoPrivateMessage):
await context.author.send('This command cannot be used in private messages.')
elif isinstance(error, commands.DisabledCommand):
message = 'Sorry. This command is disabled and cannot be used.'
try:
await context.author.send(message)
except discord.Forbidden:
await context.send(message)
elif isinstance(error, commands.UserInputError):
await context.send(error)
elif isinstance(error, commands.NotOwner):
logger.error('%s tried to run %s but is not the owner', context.author, context.command.name)
elif isinstance(error, commands.CommandInvokeError):
await context.send('An internal error occured while trying to run that command.')
logger.error('In %s:', context.command.qualified_name)
logger.error(''.join(traceback.format_tb(error.original.__traceback__)))
# pylint: disable=logging-format-interpolation
logger.error('{0.__class__.__name__}: {0}'.format(error.original))
2018-07-30 03:48:58 +00:00
bot = Bot()
if __name__ == '__main__':
bot.run()