Hi, I need help with a miscord bot written in python that uses artificial intelligence. it is a simple bot because it just starts with the project. Unfortunately already at this level something breaks and i can’t understand why. Below i’m posting the code of my bot. When i fire it up everything works fine, but when i try to send any command it doesn’t work or displays that the bandwidth limit has been used up. When i go to the openai website everything is fine and when the bot responds to any command it writes me in the terminal to check my plan. I don’t understand anything. As i wrote earlier i’m posting the code (of course, in places where there should be secret codes in the original code, but there are none in the shared one, due to security reasons):
import discord
from discord.ext import commands
import openai
openai.api_key =
TOKEN =
intents = discord.Intents.all()
bot = commands.Bot(command_prefix='!', intents=intents)
response_cache = {}
@bot.event
async def on_command_error(ctx, error):
if isinstance(error, commands.CommandOnCooldown):
await ctx.send(f'To polecenie jest obecnie na czasie odstępu. Spróbuj ponownie za {error.retry_after:.2f} sekund.')
elif isinstance(error, commands.MissingRequiredArgument):
await ctx.send('Brakuje argumentu. Upewnij się, że wprowadziłeś wszystkie wymagane argumenty.')
else:
await ctx.send(f'Wystąpił błąd: {error}')
@bot.event
async def on_ready():
print("Bot jest gotowy.")
channel = bot.get_channel(CHANNEL_ID)
await channel.send("Cześć, jestem gotowy do działania!")
@bot.event
async def on_message(message):
if message.author == bot.user:
return
prompt = message.content
if prompt in response_cache:
reply = response_cache[prompt]
else:
try:
response = openai.Completion.create(
engine='davinci',
prompt=prompt,
max_tokens=50,
temperature=0.7
)
reply = response.choices[0].text.strip()
response_cache[prompt] = reply
except openai.error.RateLimitError as e:
await message.channel.send(f'Przekroczono limit przepustowości. Sprawdź swój plan i szczegóły dotyczące faktur.')
return
except Exception as e:
await message.channel.send(f'Wystąpił błąd OpenAI: {e}')
return
await message.channel.send(reply)
@bot.command()
async def yo(ctx):
await ctx.send("Cześć!")
bot.run('')