Code :
import discord
import asyncio
from PyMySQL import pymysql
# Código sin importancia
if message.content.startswith('!points'):
clist = message.content.split(' ')
if len(clist) > 1:
# Código sin importancia
else:
cursor.execute("SELECT * FROM usuario where discord_id = "+str(message.author.id))
bdb=cursor.fetchall()
print (bdb)
for usuario in bdb:
puntos=usuario[3]
await client.send_message(message.channel, content=('Tienes '+str(puntos)+' puntos!'))
I'm using the modules of discord.py , asyncio and PyMySQL in Python3.5. A different script adds points in the database every 10 seconds. There is more code, but basically what it does is detect new messages in discord that start with ! Points , and then check if you have only sent ! Points or if you have sent ! points [something] .
Problem :
The problem comes when they send only ! points (in else:
). Does the search cursor.execute("SELECT * FROM usuario where discord_id = "+str(message.author.id))
. And it ends up taking out the amount of points that the person has.
The first search does perfectly, and sends the points that person has at that exact moment, but the next time you put ! Points , the value is always the same value that came out the first once .
I guess the error is in these lines
cursor.execute("SELECT * FROM usuario where discord_id = "+str(message.author.id))
bdb=cursor.fetchall()
How could I fix the error I said? Are there better ways to do the search?