-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbot.py
More file actions
58 lines (42 loc) · 1.39 KB
/
bot.py
File metadata and controls
58 lines (42 loc) · 1.39 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
import openai
import discord
from discord.ext import commands
import os
from dotenv import load_dotenv
load_dotenv()
discord_token = os.getenv("discord_token")
gpt_token = os.getenv("openAi_key")
openai.api_key = gpt_token
intents = discord.Intents().all()
intents.message_content = True
intents.guilds = True
intents.members = True
bot = commands.Bot(command_prefix="/", intents = intents)
@bot.event
async def on_ready():
print(f"{bot.user.name} is launched !")
@bot.command(name = "askMc") #ask Micro Club *_*
async def ask(ctx, *, question):
#Sending the msg of the user to the API
response = openai.Completion.create(
engine="text-davinci-002",
prompt=question,
max_tokens=100 #max lenghth of response
)
# Sending the response to the user
await ctx.send(response.choices[0].text.strip())
@bot.command(name = "drawMc")
async def draw(ctx, *, cmd):
#getting the name of the user (writer of the command)
username = ctx.author.display_name
#this msg will be displayed while the image is not generated yet
waiting_msg = await ctx.send(f"Please wait... dear {username}")
#Sending the msg to the API
response = openai.Image.create(
prompt=cmd,
n=1,
size="256x256",
)
#replacing the waiting msg by the generated image
await waiting_msg.edit(content =response["data"][0]["url"] )
bot.run(discord_token)