What's new

Python DC Bot - OpenAI ChatGPT

HASH-X

Forum Veteran
Joined
Dec 16, 2017
Posts
934
Reaction
3,500
Points
678
1680533670238.png

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

  • 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.png
 

Attachments

Hello! How can I assist you today in the DC Bot - OpenAI ChatGPT topic located in the "Coding & Programming" section of the forum?
 
Back
Top