#Chat GPT 3 in a discord bot

15 messages · Page 1 of 1 (latest)

silent gulch
#

I am trying to use Chat GPT 3 in a discord bot but I am recieving a rate limit error.

import openai
import discord

Replace with your Discord bot token

DISCORD_BOT_TOKEN = "MY BOT TOKEN"

Replace with your OpenAI API key

OPENAI_API_KEY = "MY API KEY"

Check if the required libraries are installed

try:
import openai
import discord
except ImportError:
print("Error: One or more required libraries are not installed.")
print("Please install the 'openai' and 'discord' libraries and try again.")
exit(1)

Check if the Discord bot token and OpenAI API key are set

if not DISCORD_BOT_TOKEN or not OPENAI_API_KEY:
print("Error: The Discord bot token and OpenAI API key are not set.")
print("Please set the DISCORD_BOT_TOKEN and OPENAI_API_KEY variables and try again.")
exit(1)

Initialize the OpenAI API client

openai.api_key = OPENAI_API_KEY

Initialize the Discord client

intents = discord.Intents.all()
client = discord.Client(intents=intents)

@client.event
async def on_message(message):

Check if the message is from the bot itself

if message.author == client.user:
return

Use the OpenAI API to generate a response to the user's message

try:
response = openai.Completion.create(
engine="text-davinci-002",
prompt=message.content,
max_tokens=1024,
temperature=0.5,
)
except openai.errors.OpenAIError as err:
print(f"Error: An error occurred while using the OpenAI API: {err}")
return

Send the response back to the user

try:
await message.channel.send(response["choices"][0]["text"])
except discord.errors.DiscordException as err:
print(f"Error: An error occurred while using the Discord API: {err}")
return

try:
client.run(DISCORD_BOT_TOKEN)
except discord.errors.DiscordException as err:
print(f"Error: An error occurred while starting the Discord bot: {err}")
exit(1)

frigid coyote
#

Try something else

jagged ginkgo
# silent gulch I am trying to use Chat GPT 3 in a discord bot but I am recieving a rate limit e...

import openai
import discord

DISCORD_BOT_TOKEN = "DISCORD BOT TOKEN"
OPENAI_API_KEY = "API KEY HERE"
PREFIX = ">" # Set the prefix for the command

Check if the required libraries are installed

try:
import openai
import discord
except ImportError:
print("Error: One or more required libraries are not installed.")
print("Please install the 'openai' and 'discord' libraries and try again.")
exit(1)

Check if the Discord bot token and OpenAI API key are set

if not DISCORD_BOT_TOKEN or not OPENAI_API_KEY:
print("Error: The Discord bot token and OpenAI API key are not set.")
print("Please set the DISCORD_BOT_TOKEN and OPENAI_API_KEY variables and try again.")
exit(1)

Initialize the OpenAI API client

openai.api_key = OPENAI_API_KEY

Initialize the Discord client

intents = discord.Intents.all()
client = discord.Client(intents=intents)

@client.event
async def on_message(message):

Check if the message is from the bot itself or doesn't start with the prefix

if message.author == client.user or not message.content.startswith(PREFIX):
return

Extract the command and arguments from the message

command, *args = message.content[len(PREFIX):].split()

Only process the "prompt" command

if command == "prompt":
# Use the OpenAI API to generate a response to the user's prompt
try:
response = openai.Completion.create(
engine="text-davinci-003",
prompt=" ".join(args[1:]), # Only include the input after the "prompt" command as the prompt
max_tokens=1024,
temperature=0.80,
)
except openai.errors.OpenAIError as err:
print(f"Error: An error occurred while using the OpenAI API: {err}")
return

# Send the response back to the user
try:
  await message.channel.send(response["choices"][0]["text"])
except discord.errors.DiscordException as err:
  print(f"Error: An error occurred while using the Discord API: {err}")
  return

try:
client.run(DISCORD_BOT_TOKEN)
except discord.errors.DiscordException:
print("Error connecting to Discord")

#

that should work

inland idol
#

Ask chatgpt 💀

jagged ginkgo
#

fr

hollow oar
jagged ginkgo
#

just the one in quotes

hollow oar
# jagged ginkgo just the one in quotes

I got this response when running it:

[2022-12-21 00:28:38] [INFO ] discord.client: logging in using static token
[2022-12-21 00:28:39] [INFO ] discord.gateway: Shard ID None has connected to Gateway (Session ID: c94b0f8a1c290c627f36893ede445289).

But whenever I type the prefix and then my message, nothing happens. You know why?

jagged ginkgo
#

it works for me

#

ask chat gpt

#

lmao

hollow oar
#

I'm trying to rn 😆 Can I DM you really quick? If you don't mind of course

jagged ginkgo
#

ofc

halcyon spoke
#

x