#MongoDB cant get an item to be added to a shop schema

1 messages · Page 1 of 1 (latest)

broken holly

hi, so basically im very lost, im trying to make it so a bot can have a custom shop with itemName, itemPrice and itemDescription, my shopItemModel.js: ```const { Schema, model } = require("mongoose");

const shopItemSchema = new Schema({
itemName: String, // Name of the item
itemPrice: Number, // Price of the item
itemDescription: String, // Description of the item
});

module.exports = model("ShopItem", shopItemSchema, "itemShop");the add-shop-item.js code:// commands/additem.js

const { CommandInteraction, MessageEmbed } = require('discord.js');
const ShopItem = require('../../schemas/shopItemModel');

module.exports = {
data: {
name: 'add-shop-item',
description: 'Add an item to the shop',
options: [
{
name: 'name',
type: 'STRING',
description: 'Name of the item',
required: true,
},
{
name: 'price',
type: 'INTEGER',
description: 'Price of the item',
required: true,
},
{
name: 'description',
type: 'STRING',
description: 'Description of the item',
required: true,
},
],
},
async execute(interaction) {
try {
const itemName = interaction.options.getString('name');
const itemPrice = interaction.options.getInteger('price');
const itemDescription = interaction.options.getString('description');

  const newItem = new ShopItem({
    itemName,
    itemPrice,
    itemDescription,
  });

  await newItem.save();

  const embed = new MessageEmbed()
    .setTitle('Item Added to Shop')
    .setColor('#27ae60')
    .setDescription(`Item: ${itemName}\nPrice: $${itemPrice}\nDescription: ${itemDescription}`);

  await interaction.reply({ embeds: [embed] });
} catch (error) {
  console.error(error);
  await interaction.reply('An error occurred while adding the item to the shop.');
}

},
};