0

I have a function that is called by using

console.log(getGuildChance(message.guild.id));

and it keeps returning Promise { undefined }, here is the function:

async function getGuildChance(guildId) {
    let db = new sqlite.Database('./servers.db', sqlite.OPEN_READWRITE | sqlite.OPEN_CREATE)
    let query = `SELECT * FROM servers WHERE serverid = ?`;
    db.get(query, [guildId], (err, row) => {
        if (err) {
            console.log(err)
            return;
        }
        return row.chance;
    });
}

im a bit lost on what to do, ive already tried using promises but i cant seem to get it. please help and thank you in advance

  • put `return` before `db.get(...)`. And this function doesn't need to be marked as `async`, assuming `db.get` returns a Promise. – Robin Zigmond Aug 05 '21 at 22:53
  • @RobinZigmond It doesn't appear to return a promise – Bergi Aug 05 '21 at 22:54
  • See the canonical question on how to create promises, also [these](https://stackoverflow.com/q/39580345/1048572) [two questions](https://stackoverflow.com/questions/36111106/nodejs-sqlite3-db-run-as-a-bluebird-promise) have specific examples with `sqlite`. If that doesn't help, please [edit] your question to include the code of your attempts at using promises. – Bergi Aug 05 '21 at 22:56

0 Answers0