0

I'm making a userinfo command that returns items from a .db file but it returns as [object Object]. How do i make it so it returns the names? heres my code:

const { MessageEmbed } = require(`discord.js`)
const db = require(`quick.db`);

exports.execute = async(client, message, args) => {
    let member = message.mentions.members.first() || message.member;
    let hasStarted = db.fetch(`started_${member.id}`)
    let bal = db.fetch(`money_${member.id}`)
    let items = db.get(`items_${member.id}`)
    let displayItems;
    let started;

    if (bal === null) bal = 0;
    if (items === null) {
        displayItems = 'This user has no items!';
    } else {
        displayItems = items;
    }
    if (hasStarted === null) {
        started = 'False'
    } else {
        started = 'True'
    }

    const userEmbed = new MessageEmbed()
    .setTitle(member.displayName + '#' + member.user.discriminator + "'s Profile")
    .addField(`Balance:`, bal)
    .addField(`Items:`, displayItems)
    .addField(`Has Started:`, started)
    .setFooter(`Requested By: ${message.author.username}`, message.author.avatarURL({ dynamic:true }))
    .setImage(member.user.avatarURL({ dynamic:true }))
    message.channel.send(userEmbed)
}

exports.help = {
    name: 'userinfo',
    aliases: ['user'],
    usage: 'userinfo <user>'
}
Hyphon
  • 9
  • 2
  • 1
    when `[object Object]` gets displayed, it means that the thing you are trying to display is an object. Try to `console.log()` to see what is in that object. – Worthy Alpaca Nov 07 '20 at 18:18
  • Quick.db is a promise based node package. When something is promise based it usually means you have to await for them. Remembering that you can only await items in an async function. – Tyler2P Nov 07 '20 at 19:03

2 Answers2

0

Discord doesn't send objects, but strings. If the data is an Object, you should try:

// Send this, not object:
c.send(JSON.stringify(object)) // Also, you should wrap in a code block with the JSON language, it'll look much nicer

If it's a Promise, you should try:

c.send(await promise)
deb
  • 6,671
  • 2
  • 11
  • 27
0

try this

let member = message.mentions.members.first() || message.member;
let hasStarted = db.fetch(`started_${member.id}`)
let bal = db.fetch(`money_${member.id}`)
let items = db.get(`items_${member.id}`)
let displayItems;
let started;

if (bal === null) bal = 0;
if (items === null) {
    displayItems = 'This user has no items!';
} else {
    displayItems = items;
}
if (hasStarted === null) {
    started = 'False'
} else {
    started = 'True'
}

const userEmbed = new MessageEmbed()
.setTitle(member.displayName + '#' + member.user.discriminator + "'s Profile")
.addField(`Balance:`, `${bal}`)
.addField(`Items:`, `${displayItems}`)
.addField(`Has Started:`, `${started}`)
.setFooter(`Requested By: ${message.author.username}`, message.author.avatarURL({ dynamic:true }))
.setImage(member.user.avatarURL({ dynamic:true }))
message.channel.send({embeds: [userEmbed}})
xein
  • 1
  • Consider adding more of a description to what the code does and how it addresses the issue. – benhorgen Sep 13 '21 at 15:45
  • 1
    Your answer could be improved with additional supporting information. Please [edit] to add further details, such as citations or documentation, so that others can confirm that your answer is correct. You can find more information on how to write good answers [in the help center](/help/how-to-ask). – Community Sep 13 '21 at 15:46