Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

265
Vistas
How to use quick.db variable in client.users.fetch discordjs

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.

about 4 years ago · Santiago Gelvez
1 Respuestas
Responde la pregunta

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
about 4 years ago · Santiago Gelvez Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda