对于在Discord.JS中制作的Discord机器人,我有以下代码
if(msg.content.startsWith(prefix+'bank')){
var i = 0
var total = 0
sql.run("SELECT SUM(money) FROM money");
msg.channel.send('** :earth_americas: | The current *GLOBAL* bank is worth e$'+total+'.**')
}
我得到了错误:
sql.run("SELECT SUM(money) FROM money");
^
TypeError: sql.run is not a function
at Client.client.on.msg (/Users/jack/Documents/Code/EcoBot/bot.js:105:16)
at emitOne (events.js:96:13)
at Client.emit (events.js:188:7)
at MessageCreateHandler.handle (/Users/jack/Documents/Code/EcoBot/node_modules/discord.js/src/client/websocket/packets/handlers/MessageCreate.js:9:34)
at WebSocketPacketManager.handle (/Users/jack/Documents/Code/EcoBot/node_modules/discord.js/src/client/websocket/packets/WebSocketPacketManager.js:103:65)
at WebSocketConnection.onPacket (/Users/jack/Documents/Code/EcoBot/node_modules/discord.js/src/client/websocket/WebSocketConnection.js:333:35)
at WebSocketConnection.onMessage (/Users/jack/Documents/Code/EcoBot/node_modules/discord.js/src/client/websocket/WebSocketConnection.js:296:17)
at WebSocket.onMessage (/Users/jack/Documents/Code/EcoBot/node_modules/ws/lib/event-target.js:120:16)
at emitOne (events.js:96:13)
at WebSocket.emit (events.js:188:7)
在这里定义sql
:
const SQLite = require("better-sqlite3");
const sql = new SQLite('./money.sqlite');
我试图找到答案,我已经浏览了文档,但是却一无所获。文件是here。任何帮助都将受到赞赏。
答案 0 :(得分:0)
在Better-sqlite3文档中,它使用以下语法。
var qry = db.prepare("SELECT SUM(money) AS total FROM money").get()
total = qry.total
已阅读文档here