Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

266
Visualizações
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 Respostas
Responde à pergunta

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 Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda