As @Lemix said in comment, sql.get
is an async function and the console.log
would be executed before it is done.
Also be aware of the variable scope. var UserMurderCoins
is defined inside a then
function and is accessed out of the scope. So, it wouldn't be defined even if the statement was executed after the sql.get.then
.
you can either run the console.log
inside the then
function or define the variable globally and only assign it inside the then
function.
UPDATE:
To be more comfortable with promises, you can use async await
syntax.
I modified your code with a little changes to be working.
async function f() {
var UserMurderCoins = (await sql.get(`SELECT * FROM monney WHERE userId ="${message.author.id}"`)).coins;
console.log(UserMurderCoins);
}
f();