#data returns undefined

7 messages · Page 1 of 1 (latest)

runic swan
#

can anyone point out what im doing wrong here? even if i have data or no data in my database, it still returns undefined

Node ver: v16.16.0

const { SlashCommandBuilder, EmbedBuilder } = require('discord.js');
const starboard_schema = require('../../Schemas/starboard-schema')

module.exports = {
    data: new SlashCommandBuilder()
        .setName('settings')
        .setDescription(`test`),

    async execute(interaction) {
        const { guild } = interaction
        
        const embed = new EmbedBuilder()
        .setDescription(`No data.`)
        .addFields([
            { name: `starboard`, value: `> no data`, inline: true },
        ]);
        
        let data = starboard_schema.findOne({ guild: guild.id });
        
        if (data) {
            embed.setDescription(`data`)
            embed.spliceFields(0, 1, { name: `starboard`, value: `> Channel: ${data.channel}, Emoji: ${data.emoji}`, inline: true  });
        }

        await interaction.reply({ embeds: [embed], ephemeral: true })
    }

}

starboard-schema.js

const mongoose = require('mongoose');

const starboard = new mongoose.Schema({
    guild: String,
    channel: String,
    emoji: String,
    count: Number,
    color: String,
});

module.exports = mongoose.model('Starboard', starboard);
honest schoonerBOT
#

• What's your exact discord.js npm list discord.js and node node -v version?
• Post the full error stack trace, not just the top part!
• Show your code!
• Explain what exactly your issue is.
• Not a discord.js issue? Check out #useful-servers.

untold urchin
#

whatever data is doesn't have those properties, or they are undefined

gilded axle
#

console log data ^

runic swan
vital pulsar
#

This isnt a discord.js issue

#

The object is a Query, probably because you didnt await it