javascript object misbehaving

I have no clue why this is happening
11 Replies
d.js toolkit
d.js toolkit3mo ago
- What's your exact discord.js npm list discord.js and node node -v version? - Not a discord.js issue? Check out #other-js-ts. - Consider reading #how-to-get-help to improve your question! - Explain what exactly your issue is. - Post the full error stack trace, not just the top part! - Show your code! - Issue solved? Press the button!
! MYA
! MYAOP3mo ago
Heres my src
const { SlashCommandBuilder, EmbedBuilder } = require("discord.js");
const UserCurrencyProfile = require("../../models/userCurrencyProfile");

module.exports = {
data: new SlashCommandBuilder()
.setName("balance")
.setDescription("Check a balance")
.addUserOption(option => option.setName("user").setDescription("user you want to check the balance of.").setRequired(false)),

/**
* @typedef {Object} RunOptions
* @property {import("discord.js").Interaction} interaction
*/

/**
*
* @param {RunOptions} options
* @returns
*/


run: async ({ interaction }) => {
try {
const userIdToSearch = (interaction.options.getUser("user") || interaction.user).id
const userObject = await UserCurrencyProfile.findOne({ "userid": userIdToSearch })

console.log(userObject)

const walletValue = toString(userObject["wallet"])
const bankValue = toString(userObject["bank"])

console.log(walletValue)

const balanceEmbed = new EmbedBuilder()
.setTitle("Balance")
.setDescription("Shows the balance of the user")
.addFields(
{name: "wallet", value: walletValue},
{name: "bank", value: bankValue}
)
.setColor("Green")
await interaction.reply({embeds: [balanceEmbed]})
} catch (error) {
console.log(error)
}


}


}
const { SlashCommandBuilder, EmbedBuilder } = require("discord.js");
const UserCurrencyProfile = require("../../models/userCurrencyProfile");

module.exports = {
data: new SlashCommandBuilder()
.setName("balance")
.setDescription("Check a balance")
.addUserOption(option => option.setName("user").setDescription("user you want to check the balance of.").setRequired(false)),

/**
* @typedef {Object} RunOptions
* @property {import("discord.js").Interaction} interaction
*/

/**
*
* @param {RunOptions} options
* @returns
*/


run: async ({ interaction }) => {
try {
const userIdToSearch = (interaction.options.getUser("user") || interaction.user).id
const userObject = await UserCurrencyProfile.findOne({ "userid": userIdToSearch })

console.log(userObject)

const walletValue = toString(userObject["wallet"])
const bankValue = toString(userObject["bank"])

console.log(walletValue)

const balanceEmbed = new EmbedBuilder()
.setTitle("Balance")
.setDescription("Shows the balance of the user")
.addFields(
{name: "wallet", value: walletValue},
{name: "bank", value: bankValue}
)
.setColor("Green")
await interaction.reply({embeds: [balanceEmbed]})
} catch (error) {
console.log(error)
}


}


}
heres the embed that it returns
! MYA
! MYAOP3mo ago
No description
! MYA
! MYAOP3mo ago
I initially thought it was a problem with the data type that I was passing through to the embed
Mark
Mark3mo ago
And that are the values of your DB query
! MYA
! MYAOP3mo ago
yes
! MYA
! MYAOP3mo ago
No description
Mark
Mark3mo ago
Check the values of userObject["wallet"] etc and what your toString method returns This is not related to d.js, this is you parsing your object
! MYA
! MYAOP3mo ago
100 (Number) Oh sorry. Should I close this and open a new post in https://discord.com/channels/222078108977594368/1081585952654360687?
Mark
Mark3mo ago
That would be one option, yes
! MYA
! MYAOP3mo ago
ok
Want results from more Discord servers?
Add your server