From 13ae53cdad2e423c14a7b46961b613d3f0c97f9a Mon Sep 17 00:00:00 2001 From: phixxy Date: Tue, 20 Feb 2024 20:56:14 -0800 Subject: [PATCH] fixed dalle3 command --- cogs/chatgpt.py | 19 +++++++++---------- src/bot.py | 4 ++++ 2 files changed, 13 insertions(+), 10 deletions(-) diff --git a/cogs/chatgpt.py b/cogs/chatgpt.py index 9a79538..bf92cfd 100644 --- a/cogs/chatgpt.py +++ b/cogs/chatgpt.py @@ -21,14 +21,13 @@ class ChatGPT(commands.Cog): self.remind_me_loop.start() self.http_session = self.create_aiohttp_session() self.logger = logging.getLogger("bot") - - def create_aiohttp_session(self): - return aiohttp.ClientSession( - headers = { + self.headers = { 'Content-Type': 'application/json', 'Authorization': f'Bearer {os.getenv("openai.api_key")}', } - ) + + def create_aiohttp_session(self): + return aiohttp.ClientSession() def folder_setup(self): try: @@ -100,7 +99,7 @@ class ChatGPT(commands.Cog): url = "https://api.openai.com/v1/chat/completions" try: - async with self.http_session.post(url, json=data) as resp: + async with self.http_session.post(url, json=data, headers=self.headers) as resp: response_data = await resp.json() response = response_data['choices'][0]['message']['content'] return response @@ -212,7 +211,7 @@ class ChatGPT(commands.Cog): url = "https://api.openai.com/v1/images/generations" try: - async with self.http_session.post(url, json=data) as resp: + async with self.http_session.post(url, json=data, headers=self.headers) as resp: response_data = await resp.json() response = response_data['data'][0]['url'] return response @@ -295,7 +294,7 @@ class ChatGPT(commands.Cog): url = "https://api.openai.com/v1/chat/completions" try: - async with self.http_session.post(url, json=data) as resp: + async with self.http_session.post(url, json=data, headers=self.headers) as resp: response_data = await resp.json() self.logger.debug(response_data) answer = response_data['choices'][0]['message']['content'] @@ -402,7 +401,7 @@ class ChatGPT(commands.Cog): url = "https://api.openai.com/v1/chat/completions" try: - async with self.http_session.post(url, json=data) as resp: + async with self.http_session.post(url, json=data, headers=self.headers) as resp: response_data = await resp.json() reaction = response_data['choices'][0]['message']['content'].strip() if is_emoji(reaction): @@ -425,7 +424,7 @@ class ChatGPT(commands.Cog): url = "https://api.openai.com/v1/chat/completions" try: - async with self.http_session.post(url, json=data) as resp: + async with self.http_session.post(url, json=data, headers=self.headers) as resp: response_data = await resp.json() response = response_data['choices'][0]['message']['content'] if "Sparkytron 3000:" in response[0:17]: diff --git a/src/bot.py b/src/bot.py index 3bb3715..ed84275 100644 --- a/src/bot.py +++ b/src/bot.py @@ -32,6 +32,10 @@ async def on_ready(): @bot.event async def on_message(ctx): + if ctx.channel.type == discord.ChannelType.private: + return + if ctx.author.bot: + return try: await bot.process_commands(ctx) except commands.CommandNotFound: