好的,下面是我创建余额为 $0 的数据库的代码,下面是一个测试命令,用于测试两个参数,以便我可以获得以下返回消息:
机器人:“${args} ${args2}”
但是,每当我用两个参数定义测试命令时,我都会收到一条错误消息SqliteError: no such table: a
(我输入了命令eco test a b
,“a”是 ${args},“b”是 ${args2}。
client.on("message", message => {
if(message.author.bot) return;
const args = message.content.slice(config.prefix.length).trim().split(' ');
const command = args.shift().toLowerCase();
if (command === "testbal") {
const table = sql.prepare(`SELECT count(*) FROM sqlite_master WHERE type='table' AND name = '${args}';`).get();
if (!table['count(*)']) {
// If the table isn't there, create it and setup the database correctly.
sql.prepare(`CREATE TABLE IF NOT EXISTS ${args} (bal TEXT);`).run();
// Ensure that the "id" row is always unique and indexed.
sql.prepare(`CREATE UNIQUE INDEX idx_${args}_id ON ${args} (bal);`).run();
sql.pragma("synchronous = 1");
sql.pragma("journal_mode = wal");
}
// And then we have two prepared statements to get and set the score data.
client.getScore = sql.prepare(`SELECT * FROM ${args} WHERE bal = ?`);
client.setScore = sql.prepare(`INSERT OR REPLACE INTO ${args} (bal) VALUES (@bal);`);
sql.prepare(`INSERT OR REPLACE INTO ${args} (bal) VALUES (0);`).run();
}
});
//Actual command now
client.on("message", message => {
const args = message.content.slice(config.prefix.length).trim().split(' ');
const command = args.shift().toLowerCase();
if (command === "bal"); {
if (message.author.bot) return;
const data = sql.prepare(`SELECT bal FROM ${args}`).get();
message.channel.send(`You have ${data.bal}`)
}
});
//TEST ARGS
client.on("message", message => {
const args = message.content.slice(config.prefix.length).trim().split(' ');
const args2 = message.content.slice(config.prefix.length).trim(args).split(' ');
const command = args.shift().toLowerCase();
if (command === `test`); {
message.channel.send(`${args} ${args2}`);
}
});
该错误来自const data = sql.prepare(`SELECT bal FROM ${args}`).get();
控制台,这很奇怪,因为我根本没有执行bal
命令,并且只执行了test
不属于代码所在的命令const data = sql.prepare(`SELECT bal FROM ${args}`).get();
。