29 lines
1.0 KiB
Python
29 lines
1.0 KiB
Python
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)) |