I am using firebase to check a users punishment history, and when I call it: I want it to return the array of embeds to post rather than just that. I am awaiting the function so I'm kind of confused why this is happening
This is what happens in the console.log:

[AsyncFunction: CheckHistory]
CALL
let hist = await CheckHistory(id);
console.log(CheckHistory);
FUNCTION
async function CheckHistory(user){
CheckBan(user);
let historyArray = [];
const colRef = db.collection('punishments')
colRef.where('user', '==', user).get().then(async querySnapshot => {
length = querySnapshot.size;
if (querySnapshot.empty){
console.log(querySnapshot.size)
return 0;
} else {
let docs = querySnapshot.docs;
for (let documentSnapshot of docs) {
const revoke = documentSnapshot.get('revoke')
let active = documentSnapshot.get('active')
if (active = true){
active = "Active"
} else {
active = `Revoked for ${revoke}`
}
const mod = documentSnapshot.get('mod')
const reason = documentSnapshot.get('reason');
const time = documentSnapshot.get('time');
let type = documentSnapshot.get('type');
if (type == 1){
type = "Blacklist";
} else if (type == 2){
type = "Dayban";
} else if (type == 3){
type = "Warning";
}
const username = await API.getUsernameFromId(user);
const modname = await API.getUsernameFromId(mod);
const historyEmbed = new MessageEmbed()
.setColor('#0099ff')
.setTitle(`'Punishment of ${username}:${user}`)
.setDescription(`This is a punishment log.`)
.addFields(
{ name: 'Status', value: `${active}`},
{ name: 'Moderator', value: `${modname}:${mod}` },
{ name: 'Reason', value: `${reason}` },
{ name: 'Type', value: `${type}` },
{ name: 'Time', value: `<t:${time}>`}
)
historyArray.push(historyEmbed);
if (historyArray.length >= length) {
return historyArray;
}
}
}
});
}
As stated by @Sergey Sosunov:
You forgot to actually return anything from your method, you should
return colRef.where('user', '==', user).get().then....Or to change
.then()callback approach to actuallyawaitone. Like:const querySnapshot = await colRef.where('user', '==', user).get();and so on.
Also, the way you call the function only returns function definition; you should pass with parameters or print the variable value equal to your function. For example:
//Sample function
function test(id) { return id; }
//Returns function definition
console.log(test)
//Returns function value
console.log(test(1))
//Print variable value
let x = test(1)
console.log(x)