Soooo 我正在尝试创建一个经济系统,但是,每当我输入消息“eco bal ${args}”(其中 args 是表的名称)时,我会得到“未定义”而不是“$0” “这应该是我需要的平衡。这是代码。
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} (id TEXT PRIMARY KEY, user TEXT, guild TEXT, bal INTEGER);`).run();
// Ensure that the "id" row is always unique and indexed.
sql.prepare(`CREATE UNIQUE INDEX idx_${args}_id ON ${args} (id);`).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 user = ? AND guild = ?`);
client.setScore = sql.prepare(`INSERT OR REPLACE INTO ${args} (id, user, guild, bal) VALUES (@id, @user, @guild, @bal);`);
}
});
//Actual code of the thing
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;
let score;
if (message.guild) {
score = client.getScore.get(message.author.id, message.content.args);
if (!score) {
score = { id: `${message.guild.id}-${message.author.id}`, user: message.author.id, guild: message.guild.id, args, bal: 0}
}
score.bal++;
}
if (message.content.indexOf(config.prefix) !==0) return;
const data = sql.prepare(`SELECT bal FROM ${args}`);
message.channel.send(`You have ${data.bal}`)
}
});
当我运行命令“eco bal”时,我得到“你有未定义”