SQLite Setup

This commit is contained in:
Soenke committed 2026-05-29 18:18:26 +02:00
1 parent 7882ba4915
commit d564756511
5 files changed
+64 -10

No files matched your search

+29
View File
@@ -0,0 +1,29 @@
import discord
from discord.ext import commands
from discord import app_commands
class DBTest(commands.Cog):
def __init__(self, bot: commands.Bot):
self.bot = bot
@app_commands.command(name="test_db", description="Tests the database connection")
async def test_db(self, interaction: discord.Interaction):
await interaction.response.defer(ephemeral=True)
try:
db_conn = self.bot.database.conn
async with db_conn.execute("SELECT 1;") as cursor:
result = await cursor.fetchone()
if result:
await interaction.followup.send("Database connection successful!")
else:
await interaction.followup.send("Database responded, but returned no data.")
except Exception as e:
await interaction.followup.send(f"Database connection failed: {e}")
async def setup(bot: commands.Bot):
await bot.add_cog(DBTest(bot))