【发布时间】:2019-05-25 22:59:27
【问题描述】:
我有一个带有名为“guildinfo”的表的 sqlite 数据库。
用于存储公会ID、bot前缀、欢迎信息、留言、bot信息、欢迎频道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!
}
【问题讨论】:
-
您似乎将 517048171084382214 作为频道 ID,将 517048171084382200 作为 WelcomeChannel,因此您似乎没有更改该值使用命令 ?welcome 或在将 DB 与输出进行比较时只是查看错误的列。
-
您能否展示将welcomeChannel id 存储到数据库中的代码?
-
添加代码+数据库图片
标签: node.js sqlite discord discord.js