🔒 Closed DC Bot - OpenAI ᑕᕼᗩTGᑭT

Status
Not open for further replies.

HASH-X

Forum Veteran
1680533670238.webp

  • HOW TO GET OpenAI API KEY?
    Code:
    https://platform.openai.com/account/api-keys
    1680536499960.webp

  • Requirements:
    Python 3.11.2
    Windows OS
  • Install Pakages
    Code:
    pip install -U py-cord
    pip install -U openai

  • Python CODE:
    Python:
    import #forbidden#
    import openai
    from #forbidden#.ext import commands
    
    openai.api_key = YOUR_API
    
    client = #forbidden#.Client()
    bot = commands.Bot(command_prefix='!', intents=#forbidden#.Intents.all())
    
    
    @bot.command()
    async def ask(ctx, *, message : str):
        response = openai.Completion.create(
        model="text-davinci-003",
        prompt=message,
        temperature=0.7,
        max_tokens=256,
        top_p=1,
        frequency_penalty=0,
        presence_penalty=0
        )
        
        embed=#forbidden#.Embed(title="🔰 MY BOT", url="YOUR_SITE_URL", description="Powered by OpenAI")
        embed.set_thumbnail(url="YOUR_IMAGE_URL")
        embed.add_field(name="✔ Question", value=message, inline=False)
        embed.add_field(name="✔ Resoponse", value=response['choices'][0]['text'], inline=True)
        await ctx.send(embed=embed)
    
    @bot.event
    async def on_command_error(ctx, error):
        if isinstance(error, commands.CommandNotFound):
            await ctx.send("Unknown command.")
            
            
    bot.run(TOKEN)
  • COMMAND: !ask
    Ex: !ask what is AI?
1680536701108.webp
 
Hello! How can I assist you today in the DC Bot - OpenAI ᑕᕼᗩTGᑭT topic located in the "Coding & Programming" section of the forum?
 
Status
Not open for further replies.

About this Thread

  • 3
    Replies
  • 794
    Views
  • 3
    Participants
Last reply from:
hannyjoy1996

Trending Topics

Online now

Members online
335
Guests online
1,101
Total visitors
1,436

Forum statistics

Threads
2,273,575
Posts
28,950,428
Members
1,235,837
Latest member
ninzi
Back
Top