Traceback (most recent call last): sqlite3.ProgrammingError: Cannot operate on a closed…
- User
Traceback (most recent call last): sqlite3.ProgrammingError: Cannot operate on a closed database.
How do I make it on my discord.py code so that if the database is closed, it opens it again?
@bot.tree.command(name="info", description="View extra information about current reference body") async def planetinfo(interaction: discord.Interaction): user_id = interaction.user.id user = c.execute("SELECT * FROM users WHERE user_id=?", (user_id,)).fetchone()
code# Fetch the current planet ID for the user current_planet_id = user[3] # If the user has a current planet, fetch the planet info if current_planet_id: planet = c.execute("SELECT * FROM planets WHERE id=?", (current_planet_id,)).fetchone() system_name = c.execute("SELECT name FROM systems WHERE id=?", (planet[3],)).fetchone() # Fetch planet name c.execute("SELECT name FROM planets WHERE id=?", (current_planet_id,)) planet_name = c.fetchone() if planet_name: planet_name = planet_name[0] # Fetch description and media URL from planet_media m.execute("SELECT description, media_url FROM planet_media WHERE planet_id=?", (current_planet_id,)) media_info = m.fetchone() dbmedia.close() if media_info: description, media_url = media_info else: description, media_url = "No description available.", None planet_desc = f"- Origin: {system_name[0]} System\n" \ f"- Type: {planet[2]}\n" \ f"- Moons: {planet[4]}\n" \ f"- Distance from Host: {planet[5]} AU\n" \ f"- Size Index: {planet[7]}\n" \ f"- Mass: {planet[9]}\n" \ f"{'- Jumpgate Planet' if planet[6] else ''}\n\n" # Create the embed embed = discord.Embed(title=f"{planet_name}", description=planet_desc + description, color=0x00ff00) # Add image if available if media_url: embed.set_image(url=media_url) # Create the button and attach it to the view view = View() view.add_item(SystemInfoButton(system_id=planet[3], system_name=system_name)) # Send the embed await interaction.response.send_message(embed=embed, view=view) else: await interaction.response.send_message("Information for current object not found") - Assistant