在 sqlite 数据库中存储不和谐频道 ID 的问题
Issues with storing discord channel ID in sqlite DB
我有一个带有 table 的 sqlite 数据库,名为 "guildinfo"。
用于存储公会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.)
这个 returns - 这看起来像 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!
}
我的数据库是这样的 -
这似乎是 node.js 数字工作方式的问题。
在 9,007,199,254,740,991
之后,即 Number.MAX_SAFE_INTEGER
( see ) 节点将 "round" 编号。
如果我使用 node.js eval 和 eval 517048171084382214
它returns 517048171084382200
Type: Number
.
这意味着您应该检查:
- 在您的数据库中,
channelId
列是 string
而不是数字
- 您的 SQL 查询没有将字符串转换为数字。
我有一个带有 table 的 sqlite 数据库,名为 "guildinfo"。
用于存储公会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.)
这个 returns - 这看起来像 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!
}
我的数据库是这样的 -
这似乎是 node.js 数字工作方式的问题。
在 9,007,199,254,740,991
之后,即 Number.MAX_SAFE_INTEGER
( see ) 节点将 "round" 编号。
如果我使用 node.js eval 和 eval 517048171084382214
它returns 517048171084382200
Type: Number
.
这意味着您应该检查:
- 在您的数据库中,
channelId
列是string
而不是数字 - 您的 SQL 查询没有将字符串转换为数字。