174
rated 0 times
[
175]
[
1]
/ answers: 1 / hits: 20545
/ 6 Years ago, wed, august 15, 2018, 12:00:00
I am trying to create a bot for the discord platform that will search a SQL database and return the objects to the chat for people to see.
SQL uses promises and I have been unable to successfully turn the promise it is returning me into something I can return to the chat (a string or array).
This code queries the database:
function spell(name) {
var spellData = sql.get("SELECT * FROM spells WHERE LOWER(name) = '"+ name.toLowerCase() + "'");
spellData.then( value => {
console.log(spellData)
return spellData;
});
}
The table:
CREATE TABLE spells (
`name` VARCHAR(25),
`casting_time` VARCHAR(95),
`components` VARCHAR(215),
`description` VARCHAR(3307),
`duration` VARCHAR(52),
`level` INT,
`range` VARCHAR(28),
`school` VARCHAR(13)
);
I'm using node.js, sqlite, and discord.js.
More From » node.js