Advertisement
TNFModding

test

May 1st, 2023 (edited)
101
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.25 KB | None | 0 0
  1. import os
  2. import openai
  3. import discord
  4. from discord.ext import commands
  5.  
  6. # Set your Discord bot token and OpenAI API key
  7. DISCORD_TOKEN = 'MTEwMjQ0NzYwODA3NDYwMDYwMQ.GlZzg8.MA9TbVYQE97tjcMReX9K8HXiSLlgjBv9WbpApE'
  8. OPENAI_API_KEY = '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'
  9.  
  10. # Initialize the OpenAI API
  11. openai.api_key = OPENAI_API_KEY
  12.  
  13. # Set up the Discord bot
  14. intents = discord.Intents.default()
  15. intents.typing = False
  16. intents.presences = False
  17.  
  18. bot = commands.Bot(command_prefix='!', intents=intents)
  19.  
  20. @bot.event
  21. async def on_ready():
  22. print(f'{bot.user} has connected to Discord!')
  23.  
  24. @bot.command(name='chat', help='Chat with the ChatGPT AI.')
  25. async def chat(ctx, *, prompt: str):
  26. # Call the OpenAI API to get a response
  27. response = openai.Completion.create(
  28. model="gpt-4",
  29. messages=[
  30. {"role": "system", "content": "You are a helpful assistant."},
  31. {"role": "user", "content": "Who won the world series in 2020?"},
  32. {"role": "assistant", "content": "The Los Angeles Dodgers won the World Series in 2020."},
  33. {"role": "user", "content": "Where was it played?"}
  34. ]
  35. )
  36.  
  37. # Send the AI's response to the user
  38. await ctx.send(response.choices[0].text.strip())
  39.  
  40. bot.run(DISCORD_TOKEN)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement