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

326
Views
DJS no puede leer las propiedades de null (leyendo 'premium')

En mi código, antes de que haga algo, verifico si hay data y, si no los hay, hago una nueva colección de mongodb, pero cuando ejecuto el comando y no hay colección, devuelve el error Cannot read properties of null (reading 'premium') y luego crea la colección mongodb, así que cuando la ejecuto por segunda vez funciona, ¿cómo haría que la colección se creara primero y luego ejecutara el comando?

Código:

 run: async (interaction, client) => { const data = await guildSchema.findOne({ id: interaction.guild.id }); if (!data) { const newData = new guildSchema({ id: interaction.guild.id, name: interaction.guild.name }) newData.save(); } const types = interaction.options.getString('type'); const modules = interaction.options.getString('module'); if (types === 'type_enable') { if (modules === 'module_all') { if (!data.premium) { await guildSchema.findOneAndUpdate({ logChannel: interaction.options.getChannel("channel").id, welcomeChannel: interaction.options.getChannel("channel").id, goodbyeChannel: interaction.options.getChannel("channel").id, }) await guildSchema.findOneAndUpdate(filter, update, { new: true }) interaction.reply('test') } } } }
about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

Si está asignando la variable y luego creando el documento si no encuentra un documento, deberá recuperar de la base de datos nuevamente después de crear el nuevo documento.

 if (!data) { const newData = new guildSchema({ id: interaction.guild.id, name: interaction.guild.name }) newData.save(); data = await guildSchema.findOne({ id: interaction.guild.id }); }
about 4 years ago · Juan Pablo Isaza Report
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!