import os import logging import logging.handlers import discord from dotenv import load_dotenv # Set discord library logging level to INFO # Configure logging to disk and stderr discordpy_logger = logging.getLogger('discord') discordpy_logger.setLevel(logging.INFO) logger = logging.getLogger('frogbot') logger.setLevel(logging.DEBUG) stderr_loghandler = logging.StreamHandler() loghandler = logging.handlers.RotatingFileHandler( filename='frogbot.log', encoding='utf-8', maxBytes=128 * 1024 * 1024, # 128 MiB backupCount=10, # Rotate through 10 files ) logger_dt_fmt = '%Y-%m-%d %H:%M:%S' logger_formatter = logging.Formatter('[{asctime}] [{levelname:<8}] {name}: {message}', logger_dt_fmt, style='{') loghandler.setFormatter(logger_formatter) stderr_loghandler.setFormatter(logger_formatter) logger.addHandler(stderr_loghandler) logger.addHandler(loghandler) discordpy_logger.addHandler(stderr_loghandler) discordpy_logger.addHandler(loghandler) # Set up discord intents intents = discord.Intents.default() intents.message_content = True client = discord.Client(intents=intents) # Grab bot tokens and other data from environment variables load_dotenv() bot_token = os.getenv("FROGTOKEN", None) logger.debug("Bot is starting...") @client.event async def on_ready(): logger.info(f'We have logged in as {client.user}') @client.event async def on_message(message): if message.author == client.user: return if message.content.startswith('$hello'): await message.channel.send('Hello!') logger.info(f"Sent hello message to {message.author}") # Suppress the default configuration since we have our own client.run(token=bot_token, log_handler=None)