0

I have a sqlite DB with a table called "guildinfo".

This is used for storing the guild ID, bot prefix, welcome message, leave message, bot message, welcome channel ID, and the starboard ID.

I created a command - ?welcome - to change welcomeChannel to the ID of the channel the command was ran in.

However, when I try to use the data I have in my DB, I get two completely different IDs.

I wrote this to test -

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.)

This returns - This looks like test2 with the ID: 516761210776059906 in: 517048171084382214. In the DB, we have 517048171084382200 for this guild.

When I check the DB manually, I have 517048171084382214

I should be getting 517048171084382214 from the DB, rather than 517048171084382200.

Any help would be appreciated.

EDIT: ?welcome command -

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!
}

My database looks like this - enter image description here

Ross231
  • 56
  • 2
  • 8
  • You appear to be getting **517048171084382214** as the channel id and **517048171084382200** as the welcomeChannel, so it would appear that you aren't changing the value with the command **?welcome** or are simply looking at the wrong columns when comparing DB to output. – MikeT Dec 28 '18 at 03:13
  • can you show the code where you store the welcomeChannel id into the database? – T. Dirks Dec 28 '18 at 08:03
  • Added the code + a picture of the database – Ross231 Dec 28 '18 at 17:10

1 Answers1

2

It seems like this is an issue with how node.js numbers work.

After 9,007,199,254,740,991 which is Number.MAX_SAFE_INTEGER ( see ) node will "round" the number.

If I use node.js eval and eval 517048171084382214

It returns 517048171084382200 Type: Number.

This means you should check that:

  • in your database that the channelId column is string and not a number
  • that your SQL query doesn't convert the string to a number.
marc_s
  • 732,580
  • 175
  • 1,330
  • 1,459
PLASMA chicken
  • 2,777
  • 2
  • 15
  • 25