Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

239
Vistas
TypeError: Cannot read properties of undefined (reading 'createLap') MongoDB, Mongoose, JavaDcript, Discord.JS

I am working on a discord bot. And, I am having issues writing to the database. I am using these three files to communicate with the database. For some reason I am getting a:

TypeError: Cannot read properties of undefined (reading 'createLap') Error. It is coming from the second file that I posted.

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
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda