#Error Connecting to Discord
27 messages · Page 1 of 1 (latest)
What is the error? You didn't actually state the error here, your print says
print(f"Error: An error occurred while using the Discord API: {err}")
What does the {err} part say when it prints out?
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
The error is the far bottom error going “Error Connecting To Discord”, not the “An error occurred while using the Discord API”.
And I’m not using the same token for both the bots, they’re 2 individual bots, but it works on 1 of them, and doesn’t on the other
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
That part indeed. To send you the exception, I’d need to write “except discord.errors.DiscordException as e:”?
try:
client.run(TOKEN)
except discord.errors.DiscordException as e:
print(e)
yeah i'm trying to do the same
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
Oh no, I accidentally uploaded my API key and everything, so I had to quickly delete it. But they are there in my script