added db test commands

This commit is contained in:
Soenke committed 2026-05-31 17:20:22 +02:00
1 parent d564756511
commit 4d34daa1e7
3 files changed
+38 -3

No files matched your search

+15
View File
@@ -7,6 +7,21 @@ class Database:
async def connect(self):
if self.conn is None:
self.conn = await aiosqlite.connect("FemBot.db")
try:
await self.conn.execute("""
CREATE TABLE IF NOT EXISTS test (
id INTEGER PRIMARY KEY AUTOINCREMENT,
message TEXT NOT NULL
)
""")
await self.conn.commit()
print("Table check/creation completed successfully.")
except aiosqlite.Error as e:
print(f"Failed to check/creation table: {e}")
return self.conn
async def close(self):
+22 -2
View File
@@ -11,9 +11,9 @@ class DBTest(commands.Cog):
await interaction.response.defer(ephemeral=True)
try:
db_conn = self.bot.database.conn
db = self.bot.database.conn
async with db_conn.execute("SELECT 1;") as cursor:
async with db.execute("SELECT 1;") as cursor:
result = await cursor.fetchone()
if result:
@@ -25,5 +25,25 @@ class DBTest(commands.Cog):
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))
+1 -1
View File
@@ -10,7 +10,7 @@ load_dotenv()
intents = discord.Intents.default()
intents.message_content = True
bot = commands.Bot(command_prefix="Warum Kann das nicht weg??? :C", intents=intents)
bot = commands.Bot(command_prefix=None, intents=intents)
@bot.event
async def on_ready():