Skip to content

Commit

Permalink
added ask frong
Browse files Browse the repository at this point in the history
  • Loading branch information
Soulsender committed Sep 7, 2024
1 parent 2738b8e commit 6e48f08
Showing 1 changed file with 34 additions and 0 deletions.
34 changes: 34 additions & 0 deletions cogs/ask-frong.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
import nextcord
from nextcord.ext import commands
from dotenv import load_dotenv
import openai
import os

openai.api_key = str(os.getenv('OPENAI_KEY'))

def ask_chatgpt(question):
response = openai.ChatCompletion.create(
model="gpt-3.5-turbo",
messages=[
{"role": "system", "content": "You are a helpful assistant."},
{"role": "user", "content": question},
]
)
return response['choices'][0]['message']['content']

class AskFrong(commands.Cog):
def __init__(self,bot):
self.bot=bot

@commands.Cog.listener()
async def on_ready(self):
print(f"ask-frong - Loaded")

# for testing add guild_ids=[guild_id]
@nextcord.slash_command(name="askfrong", description="Ask the almighty.", guild_ids=[414625175217242113])
async def askfrong(self, interaction: nextcord.Interaction, question):
answer = ask_chatgpt(question)
await interaction.response.send_message(f"{answer}")

def setup(bot):
bot.add_cog(AskFrong(bot))

0 comments on commit 6e48f08

Please sign in to comment.