1

I'm trying to make my database easier to access when I'm coding.

This is the function (located in the main bot file):

function getDB(area,argument){
  db.collection(area).doc(argument).get().then((q) => {
    
  })
}

This is how I call it: getDB('economy',msg.author.id)

When you console.log() getDB it returns nothing, but when you console.log() q.data() in the main function it does print the full string from the DB.

Console.log() snippet

How would I get it to return the database information?

1 Answers1

1

In your function you didn't specify what you wanted to do with the given information. By your code, maybe add a return statement

function getDB(area,argument){
  db.collection(area).doc(argument).get().then((q) => return q; )
}

This way you can use the database easily. here's some examples

if(getDB(balance,message.author.id)) return;
//
message.channel.send(`
${getDB(xp, message.author.id) > 200 ? 'You do not have required xp' : 'You do'}
`)
  • Still showing it's undefined, tried the message send example and that errors out. –  Sep 13 '20 at 17:31
  • maybe it's a lexical declaraction. Like `mesage` and not `message`, or maybe the database do return undefined when the database of the user is empty, or you didn't require the module idk -v- check one of those three – 87message.author.username7 Sep 13 '20 at 17:42