Skip to content
This repository was archived by the owner on Apr 11, 2025. It is now read-only.

Commit 6e48f08

Browse files
committed
added ask frong
1 parent 2738b8e commit 6e48f08

1 file changed

Lines changed: 34 additions & 0 deletions

File tree

cogs/ask-frong.py

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
import nextcord
2+
from nextcord.ext import commands
3+
from dotenv import load_dotenv
4+
import openai
5+
import os
6+
7+
openai.api_key = str(os.getenv('OPENAI_KEY'))
8+
9+
def ask_chatgpt(question):
10+
response = openai.ChatCompletion.create(
11+
model="gpt-3.5-turbo",
12+
messages=[
13+
{"role": "system", "content": "You are a helpful assistant."},
14+
{"role": "user", "content": question},
15+
]
16+
)
17+
return response['choices'][0]['message']['content']
18+
19+
class AskFrong(commands.Cog):
20+
def __init__(self,bot):
21+
self.bot=bot
22+
23+
@commands.Cog.listener()
24+
async def on_ready(self):
25+
print(f"ask-frong - Loaded")
26+
27+
# for testing add guild_ids=[guild_id]
28+
@nextcord.slash_command(name="askfrong", description="Ask the almighty.", guild_ids=[414625175217242113])
29+
async def askfrong(self, interaction: nextcord.Interaction, question):
30+
answer = ask_chatgpt(question)
31+
await interaction.response.send_message(f"{answer}")
32+
33+
def setup(bot):
34+
bot.add_cog(AskFrong(bot))

0 commit comments

Comments
 (0)