0

As title suggest, I have a bot that basically accepts 3 ints via command and stores them in a database by username and user id. i'm now trying to make a command that lets the user recall the information they submitted.

however, when I run the code, it is obtaining the bots userID instead of the userID of the person running the command. here is my code:

async def picked(ctx):
    @bot.event
    async def on_message(message):
        logger.info(f"User: '{message.author.id}' ran picked command")
    currentpick1 = cursor.execute("SELECT currentpick1 FROM nascarpool WHERE id='{message.author.id}'")
    currentlpick2 = cursor.execute("SELECT currentlpick2 FROM nascarpool WHERE id='{message.author.id}'")
    currentlpick3 = cursor.execute("SELECT currentlpick3 FROM nascarpool WHERE id='{message.author.id}'")
    cursor.execute(currentpick1, currentlpick2, currentlpick3)
    await ctx.send(f"You have registered the following picks: '{currentpick1}', '{currentlpick2}', and '{currentlpick3}'")
    cursor.close
    mydb.close

I've tried lots of different syntax. I'm new to python so I've just been reading and researching, and I really cant say specifically what I've tried over the last 12 hours trying to fix this.

racin36er
  • 3
  • 1
  • I'd suggest viewing the answers to [this question](https://stackoverflow.com/q/902408/5320906) to get an idea of how to use variables with SQL queries in Python. When you say the code retrieves the wrong value, is the value in the log message correct? What is the `ctx.send` sending? What are you expecting to send? Does the database table contain the correct data? – snakecharmerb Aug 10 '23 at 14:35
  • no. the value in the log file is the bot's user ID. i'm trying to retrieve the message sender's ID. ctx.send is sending the bots ID.... i cant figure out why its getting that and not the messager's ID instead, which is what i'm looking for. – racin36er Aug 10 '23 at 14:41
  • i should clarify, the command to submit the values is working and SQL is parsing the correct data.... but when i try to recall it, its grabbing the bots ID instead of the Users ID, which is required as thats how its stored in the database – racin36er Aug 10 '23 at 14:43
  • It isn't clear how the data you have - `message.author.id` - relates to the data in the database. Perhaps you could share the table structure (ideally the `CREATE TABLE` statement, some data and an explanation of what you are expecting to retrieve. – snakecharmerb Aug 10 '23 at 15:16

0 Answers0