#Error Connecting to Discord

27 messages · Page 1 of 1 (latest)

ancient fiber
#

So I am making my own Discord bot with GPT-3 intergrated on it, and it works on 1 of the bots, my test bot. But whenever I put it on my other one which it is actually intended to be on (They're the same bot, both running over Botghost), I'm met with "Error Connecting to Discord". This is the script:

ember ledge
#

and are you sure that you can run two different bots using the same token? That doesn't seem like it's possible to me

#

which will also explain why it works for the first time

ancient fiber
ember ledge
#

This part?

#

Can you print out the exception? We can’t tell what’s going wrong

#

make it like

#

except discord.errors.DiscordException as e:

#

and then print e

ancient fiber
# ember ledge

That part indeed. To send you the exception, I’d need to write “except discord.errors.DiscordException as e:”?

ember ledge
#
try:
    client.run(TOKEN)
except discord.errors.DiscordException as e:
    print(e)
high pollen
#

yeah i'm trying to do the same

high pollen
#

and i was able to but the bots reply was...

#

wait did it actually?

#

but the thing is it connects to completion ai instead of chatgpt and i askedhatgpt whats your model and it said itstext-davinci-003 which is same as you know it text completion ai

#

wait your code is missing import openai

#

and it should be openai.api_key = <Your api key>

#

here wait

#
import discord

DISCORD_BOT_TOKEN = "YOUR_DISCORD_BOT_TOKEN"
OPENAI_API_KEY = "YOUR_OPENAI_API_KEY"

# 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

  # Extract the command and arguments from the message
  command, *args = message.content.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),  # Include all the input after the "prompt" command as the prompt
        max_tokens=4050,
        temperature=0.7,
      )
    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("Gid3OS NOT RESPONDING, ERROR CONNECTING TO DISCORD")
#

i ain't givin' my code tho its a mess

ancient fiber