Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

246
Views
TypeError: no se pueden leer las propiedades de undefined (leyendo 'createLap') MongoDB, Mongoose, JavaDcript, Discord.JS

Estoy trabajando en un bot de discordia. Y tengo problemas para escribir en la base de datos. Estoy usando estos tres archivos para comunicarme con la base de datos. Por alguna razón estoy recibiendo un:

TypeError: no se pueden leer las propiedades de un error indefinido (leyendo 'createLap'). Viene del segundo archivo que publiqué.

 const mongoose = require('mongoose'); const lapSchema = new mongoose.Schema({ _id: mongoose.Schema.Types.ObjectId, guildId: String, memberId: String, laps:{type: Number, default: 0}, }) module.exports = mongoose.model('Lap', lapSchema, 'laps');
 const { SlashCommandBuilder } = require('@discordjs/builders'); const Lap = require('../../schemas/lap'); module.exports = { data: new SlashCommandBuilder() .setName('lap') .setDescription('It\'s been a pleasure watching you race! Let\'s take a look at your stats!') .addSubcommand(subcommand => subcommand .setName("tag-someone-else") .setDescription("Gets laps of a user that has been tagged!") .addUserOption(option => option.setName("target").setDescription("The user mentioned"))), async execute(interaction, client) { let user = (interaction.options.getUser("target") ? interaction.options.getUser("target") : interaction.user); console.log(user); const userProfile = await client.createLap(interaction.member); await interaction.reply({content: `${interaction.user.tag} has ${userProfile.laps}.`}) }, };
 const mongoose = require("mongoose"); const Lap = require('../schemas/lap'); module.exports = (client) => { client.createLap = async (member) =>{ console.log("Hitting here"); let lapProfile = await Lap.findOne({memberId: member.id, guildId: member.guild.id}); if (lapProfile){ return lapProfile; }else{ console.log("hits here") lapProfile = await new Lap({ _id: mongoose.Types.ObjectId(), guildId: member.guild.id, memberId: member.id, }); await lapProfile.save().catch(err => console.log(err)); console.log("Lap Created! This is great news."); return lapProfile; } }; };
 module.exports = (client) => { client.handleEvents = async (eventFiles, path) =>{ for (const file of eventFiles) { const event = require(`../events/${file}`); if (event.once) { client.once(event.name, (...args) => event.execute(...args, client)); } else { client.on(event.name, (...args) => event.execute(...args, client)); } } } }
about 4 years ago · Juan Pablo Isaza
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!