""" Rocketbot Discord bot. Relies on a configured config.py (copy config.py.sample for a template). Author: Ian Albert (@rocketsoup) Date: 2021-11-11 """ import traceback from discord import Intents from discord.ext import commands from config import CONFIG from cogs.configcog import ConfigCog from cogs.crosspostcog import CrossPostCog from cogs.generalcog import GeneralCog from cogs.joinraidcog import JoinRaidCog from cogs.patterncog import PatternCog from cogs.urlspamcog import URLSpamCog CURRENT_CONFIG_VERSION = 3 if (CONFIG.get('__config_version') or 0) < CURRENT_CONFIG_VERSION: # If you're getting this error, it means something changed in config.py's # format. Consult config.py.sample and compare it to your own config.py. # Rename/move any values as needed. When satisfied, update "__config_version" # to the value in config.py.sample. raise RuntimeError('config.py format may be outdated. Review ' + 'config.py.sample, update the "__config_version" field to ' + f'{CURRENT_CONFIG_VERSION}, and try again.') class Rocketbot(commands.Bot): """ Bot subclass """ def __init__(self, command_prefix, **kwargs): super().__init__(command_prefix, **kwargs) async def on_command_error(self, context: commands.Context, exception): if context.guild is None or \ context.message.channel is None or \ context.message.author.bot: return if not context.message.author.permissions_in(context.message.channel).ban_members: # Don't tell non-mods about errors return if isinstance(exception, (commands.errors.CommandError, )): # Reply with the error message for ordinary command errors await context.message.reply( f'{CONFIG["failure_emoji"]} {exception}', mention_author=False) return # Stack trace everything else traceback.print_exception(type(exception), exception, exception.__traceback__) intents = Intents.default() intents.messages = True # pylint: disable=assigning-non-slot intents.members = True # pylint: disable=assigning-non-slot bot = Rocketbot(command_prefix=CONFIG['command_prefix'], intents=intents) # Core bot.add_cog(GeneralCog(bot)) bot.add_cog(ConfigCog(bot)) # Optional bot.add_cog(CrossPostCog(bot)) bot.add_cog(JoinRaidCog(bot)) bot.add_cog(PatternCog(bot)) bot.add_cog(URLSpamCog(bot)) bot.run(CONFIG['client_token'], bot=True, reconnect=True) print('\nBot aborted')