added dev folder
This commit is contained in:
1 parent
b3c7b34863
commit
b92557b176
4 files changed
+12
No files matched your search
@@ -0,0 +1,49 @@
|
||||
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 = self.bot.database.conn
|
||||
|
||||
async with db.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}")
|
||||
|
||||
@app_commands.command(name="test_db_add", description="Add a string to the Database")
|
||||
@app_commands.describe(message="a message")
|
||||
async def test_db(self, interaction: discord.Interaction, message: str):
|
||||
await interaction.response.defer(ephemeral=True)
|
||||
|
||||
try:
|
||||
db = self.bot.database.conn
|
||||
|
||||
await db.execute(
|
||||
"INSERT INTO test (message) VALUES (?)",
|
||||
(message,)
|
||||
)
|
||||
await db.commit()
|
||||
|
||||
await interaction.followup.send("Database INSERT was successful!")
|
||||
|
||||
|
||||
except Exception as e:
|
||||
await interaction.followup.send(f"Database INSERT failed: {e}")
|
||||
|
||||
async def setup(bot: commands.Bot):
|
||||
await bot.add_cog(DBTest(bot))
|
||||
Reference in new issue
Block a user