#AFK Command with mysql
1 messages · Page 1 of 1 (latest)
why though? To prevent injection? That wouldn't even be possible in this case I think.
yes to prevent injection, may not be possible in this specific case but it's still a really bad practice
yes ok so don't use it so you don't get used to it.
Are you getting an error? Or just the bot doesn't send any message?
I get that but often one needs the whole code to understand why one section isn't working.
Lets say this line throws an error in my program: x = 5/y
With just this the error can't be found. But with the context like y = 0 it is more clear what the problem is. Do you know what I mean?
Because I couldn't find any error in this section, I was asking for your full code as this often gives a deeper insight into what is going on 🙂
Also: Please don't make pictures of your code but paste it as a code block or use pastebin for longer sections. Makes it easier for troubleshooting.
Do you get any errors?
any other console output?
well there you have your problem
await cursor.execute(f"SELECT userID FROM afk WHERE guildID = {message.guild.id}")
result = await cursor.fetchall()
somewhere there is the problem. Probably the sql query
Check if the query returns anything
Ich meine du sollst checken, ob der sql command überhaupt irgendwas zurück gibt.
na z.B. mal direkt auf deinem Datenbankserver ausführen oder mal ein kleines skript schreiben mit genau dem Befehl
@still rain
welche sql python library nutzt du denn?
.
Na ein einfaches python skript, was sich mit deinem sql server verbindet, diesen befehl sendet und das Ergebnis ausspuckt...
Ich hoffe du weißt wie das geht.
Und wie hast du dann das ganze in deinem code vom bot gemacht?
gib mir nen moment
weißt du wie du ein python skript ausführst?
war kurz weg
bin gerade dabei
pip install mysql-connector-python==8.0.29
import mysql.connector as MySQLdb
guild_id = "" # Die ID vom Discord Server
hostname = "" # Der Hostname des Servers (z.B: sql.domain.de oder eine ip)
user = "" # Der Benutzername für die Datenbank
password = "" # Das Passwort
database = "" # Der Name der Datenbank
conn: MySQLdb.MySQLConnection = MySQLdb.connect(
host=hostname, user=user, password=password, database=database
)
cursor: MySQLdb.connection.CursorBase = conn.cursor(dictionary=True)
cursor.execute("SELECT userID FROM afk WHERE guildID = %s", [guild_id])
result = cursor.fetchall()
print(result)
Das einmal im terminal ausführen
das in ne datei packen (z.b. test.py) und dann im terminal ausführen.
und natürlich die ganzen variablen oben angeben
du musst nur die "" ausfüllen hinter denen ein commentar steht
und die guild id
dann einfach ausführen und schreiben was in der konsole steht
also was geprintet wird
bin mal afk für 20 min