0
client.on("message", message => {
  const args = message.content.slice(config.prefix.length).trim().split(' ');
      const args2 = message.content.slice('test', ',', args).trim(args).split(' ', args);
  const command = args.shift().toLowerCase();
    if (command === "tbal") {
        if (message.author.bot) return;
    const data = sql.prepare(`SELECT bal FROM ${args}`).get();
      message.channel.send(`You have ${data.bal}`)
  }
  if (command == "tgive") {
    //Get their current XP
    let userscore = sql.prepare(`SELECT bal FROM ${args}`).get()
    let pointsToAdd = parseInt(args2[1], [10]);
    if(!pointsToAdd) return message.reply("How much? You didn't tell me that!");
    //XP level update
    const valueadd = sql.prepare(`INSERT OR REPLACE INTO ${args} (bal) VALUES (userscore + pointsToAdd);`)

    client.setScore.run(userscore)
    return message.channel.send(`${args} has received ${pointsToAdd}. New balance: ${data.bal}`);

}
});

There's the code, the error i'm getting is this: let userscore = sql.prepare(`SELECT bal FROM ${args}`).get()

SqliteError: near "5": syntax error

The near "5" is args2, to which I executed the command eco tgive args1 5, args1 being the name of the SQLite table.

2 Answers2

0

The arguments you pass to the 'slice' function here:

const args2 = message.content.slice('test', ',', args).trim(args).split(' ', args);

do not make any sense.

Slice takes two parameters, a beginIndex and endIndex, both numbers. This is probably where the problem originates.

When you try to use the args param in

let userscore = sql.prepare(`SELECT bal FROM ${args}`).get()

it is likely in some unexpected state.

Here's docs on the slice method: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/slice

Michael
  • 581
  • 2
  • 8
0
`SELECT bal FROM ${args}`

You need to use only the element you need from your args array as opposed to each argument. If args1 is the name of the table in the example command you provided, use this as your query, noting that args[2] is returning the third element in the array:

`SELECT bal FROM ${args[2]}`

When converting the array into a string, its elements are joined together with , and results in the malformed syntax causing your error.

slothiful
  • 5,548
  • 3
  • 12
  • 36