import logging import discord from discord.ext import commands import asyncio # Attempt to import the local settings and quit gracefully on failure try: import local_settings as settings # Environment dependant settings stored in local_settings.py, untracked by .gitinore except ModuleNotFoundError: # Local settings module import failure quit() async def main(): # Set loglevel logging.basicConfig(level=settings.LOG_LEVEL) # Define robot intents = discord.Intents.default() intents.message_content = True try: bot = commands.Bot( command_prefix="/", description="Charlie's Angels bot", intents=intents, case_insensitive=True, ) except AttributeError: quit() tree = bot.tree # Load extensions default_extensions = [ "commands.admin", "commands.general", ] for ext in default_extensions: logging.info(f"Loading extension: {ext}") await bot.load_extension(ext) await bot.start(settings.DISCORD_TOKEN) # Run robot try: asyncio.run(main()) except AttributeError: quit() except discord.errors.LoginFailure: logging.error("Invalid discord token.") quit() except KeyboardInterrupt: logging.info("Received keyboard interrupt, exiting...") quit()