add logging

This commit is contained in:
William Lane
2023-04-04 12:53:40 -07:00
parent edc79ec184
commit 7e0eeaa7ee
2 changed files with 27 additions and 12 deletions

View File

@@ -2,18 +2,28 @@ from dotenv import load_dotenv
import os
import discord
from app.mabel.connect_openai import chatgpt_response
import logging
logging.basicConfig(level=logging.INFO)
#load_dotenv()
discord_token=os.getenv('DISCORD_TOKEN')
class MyClient(discord.Client):
async def on_ready(self):
print('Logged in as: ', self.user)
logging.info('Logged in as: ', self.user)
async def on_message(self, message):
logging.info('Message from {0.author}: {0.content}'.format(message))
if message.author == client.user:
return
if "mabel" in message.content.lower():
response = await chatgpt_response(message.content)
await message.channel.send(response)
try:
response = await chatgpt_response(message.content)
except Exception as e:
logging.info('CHATGPT Error: ', e)
try:
logging.info('Response: ', response)
await message.channel.send(response)
except Exception as e:
logging.info('DISCORD Error: ', e)
return
intents=discord.Intents.default()