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

230
Visualizações
How to .get() from Firebase to integrate in Discord.JS

I'm a new JavaScript programmer facing a problem that I can't seem to solve. I'm trying to save data in a Cloud Firestore Database using Firebase and trying to save and take data from the database. I've successfully created saving data as per this code below:

db.collection("data").doc(message.author.id).set({
            "userID": message.author.id,
            "userName": message.author.tag,
            "userWallet": 500,
            "userItems": {
                "DogeCoin": 0,
                "TrollCoin": 0,
                "TrollTrophy": 0
            },
            "lastClaim": 0,
            "lastCrime": 0
        }).then(() => {
            message.channel.send(`${message.author.tag}, you have successfully created your account.`)
        })

While the saving part works the getting data part doesn't, I've tried a few methods but it still doesn't work. Right now, this is what I've worked on.

let wallet;
            let bank;
            db.collection("data").doc(message.author.id).get().then((q) => {
                if (q.exists){
                    wallet = q.data().userWallet;
                } else if(!q.exists){
                    message.channel.send(`${message.author.tag}, please go create an account.`)
                    return;
                }
            })
            let embed = new Discord.MessageEmbed()
            .setTitle(`Balance for ${message.author.tag}`)
            .setAuthor(`${client.user.tag}`)
            .setColor("RANDOM")
            .setDescription(`Created by ${client.user.tag}`)
            .addFields(
                    {name: "Bank", value: `${wallet}`}
            )
            .setImage("https://c.tenor.com/iQ7AzP7EgSAAAAAM/noice.gif")
            message.reply({embeds: [embed]})
            return;

I want to able to get the data from Firebase and use it in my code by showing it in an embed. Your help in sincerely appreciated. Thank you.

An image to show the data saved in Firebase

about 4 years ago · Juan Pablo Isaza
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