0

I am trying to use a value (Discord User ID stored as a string) stored via quick.db in my code, but it returns me the error user_id: Value "[object Promise]" is not snowflake. I've spent hours trying to figure it out but it just doesn't work. If I store the ID directly in the code it works just fine and I can fetch the user.

This is my "ready.js" file. The cron package lets me define at what time of the day that part of code is being executed. I don't think it's a part of the problem.


    const Discord = require("discord.js")
    const cron = require('cron');
    const path = require('path');
    const { QuickDB } = require("quick.db");
    const db = new QuickDB()
    
    module.exports = client => {
    
      console.log(`${client.user.username} ist online`)
      client.user.setActivity('Online!', { type: 'PLAYING' });
      
        let userid1 = db.get("id1.string");
        let scheduledMessage = new cron.CronJob('00 00 08 * * *', () => {
        client.users.fetch(userid1).then(user => {
          user.send('Test').catch(err => {
            let channel = client.channels.cache.get('998568073034465341')
            channel.send(`${user} blocked the bot`)
                  })
                })
            })
      scheduledMessage.start()
      }

This is where I want to utilize a User ID stored via quick.db in "id1.string"

client.users.fetch(userid1).then(user => {

-> This doesn't work

client.users.fetch(400120540989227010).then(user => {

-> This is working fine

I've already tried using

`${userid1}`

but this also doesn't work

I'd be so happy if someone could help me with that.

1 Answers1

0

db.get("id1.string") is an async function, meaning unless you put await behind it, it will returns a Promise who isn't finished yet. It's like wanting to send a discord message. You can't just get the message immediatly since because of your connection and the api's connection. It takes time. So to bypass this you have to use the await keyword before the .get method (and async the main function here) so that it won't execute the rest of the code until you get what you want from the database.

let userid1 = db.get("id1.string"); // What you have now
let userid1 = await db.get("id1.string"); // What you should do instead
module.exports = client => { // What you have now 
module.exports = async client => { // What you should do instead
Staxlinou
  • 1,351
  • 1
  • 5
  • 20