我有一个带有名为“ guildinfo”的表的sqlite数据库。
这用于存储行会ID,机器人前缀,欢迎消息,离开消息,机器人消息,欢迎频道ID和右舷ID。
我创建了一个命令-?welcome-来将welcomeChannel更改为运行该命令的通道的ID。
但是,当我尝试使用数据库中的数据时,会得到两个完全不同的ID。
我写这个来测试-
const info = sql.prepare(`SELECT * FROM guildinfo WHERE guild = ${message.guild.id}`)
const info2 = info.get();
console.log
(This looks like ${message.guild.name} with the ID: ${message.guild.id} in: channel ID ${message.channel.id}. In the DB, we have ${info2.welcomeChannel} for this guild.)
返回-看起来像test2,其ID为:516761210776059906,位于:517048171084382214。在数据库中,该行会有517048171084382200。
当我手动检查数据库时,我有517048171084382214
我应该从数据库中获得517048171084382214
,而不是517048171084382200
。
任何帮助将不胜感激。
编辑:?欢迎命令-
const Discord = require("discord.js");
const bot = new Discord.Client();
const path = require('path')
const SQLite = require("better-sqlite3");
const sql = new SQLite(path.join(__dirname, '../', 'db/db55.sqlite'))
const botConfig = require(path.join(__dirname, '../', "./botConfig.json"));
const prefix = botConfig.prefix;
exports.run = async (bot, message, args) => { // This function takes three arguments, the bot (client) message (full message with prefix etc.) and args (Arguments of command
if (message.author.id !== '264850435985113088') {
return message.channel.send("You shouldn't be using this command.")
}
// Get guild ID
bot.getDefaults = sql.prepare(`SELECT * FROM guildinfo WHERE guild = ${message.guild.id}`)
bot.setDefaults = sql.prepare('INSERT OR REPLACE INTO guildinfo (guild, prefix, welcomeMsg, leaveMsg, botMsg, welcomeChannel, starboard) VALUES (@guild, @prefix, @welcomeMsg, @leaveMsg, @botMsg, @welcomeChannel, @starboard);')
const info = sql.prepare(`SELECT * FROM guildinfo WHERE guild = ${message.guild.id}`)
const info2 = info.get();
let Defaults
Defaults = bot.getDefaults.get()
if (message.guild && !Defaults) {
Defaults = {
guild: `${message.guild.id}`,
prefix: prefix,
welcomeMsg: "`Welcome to ${guild.name}, ${bot.user.username}`.",
leaveMsg: "`Bye, `${bot.user.username}!`",
welcomeChannel: `${message.channel.id}`,
botMsg: null,
starboard: null
};
bot.setDefaults.run(Defaults);
message.channel.send(`Welcome messages will now be sent to ${message.channel.id} - First condition`)
} else if (sql.prepare(`SELECT * FROM guildinfo WHERE guild = ${message.guild.id}`)) {
sql.prepare(`UPDATE guildinfo SET welcomeChannel = ${message.channel.id};`).run()
message.channel.send(`Welcome messages will now be sent to ${message.channel.id} - Second condition`)
}
}
exports.help = {
name: 'welcome' // Insert your command's name here!
}
答案 0 :(得分:1)
这似乎与node.js数字的工作方式有关。
在9,007,199,254,740,991
( see )节点的Number.MAX_SAFE_INTEGER
之后将数字四舍五入。
如果我使用node.js eval和eval 517048171084382214
它返回517048171084382200
Type: Number
。
这意味着您应该检查:
channelId
列是string
而不是数字