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

127
Views
TypeError: no se pueden leer las propiedades de undefined (leyendo 'canales')

Tengo este pequeño problema en el que aparece el mensaje No se pueden leer las propiedades de un error indefinido, pero no sé dónde está el problema. ¿Puede alguien ayudarme con este?

Aquí está el código:

 const { Client } = require("discord.js"); const DB = require("../Structures/Schemas/LockDown"); /** * @param {Client} client */ module.exports = async(client) => { DB.find().then(async (documentsArray) => { documentsArray.forEach(async (d) => { const Channel = client.guilds.cache .get(d.GuildId) .channels.cache.get(d.ChannelID); if(!Channel) return; const TimeNow = Date.now(); if(d.Time < TimeNow){ Channel.permissionOverwrites.edit(d.GuildID, { SEND_MESSAGES: null, }); return await DB.deleteOne({ ChannelID: Channel.id }); } const ExpireDate = d.time - Date.now(); setTimeout(async () => { Channel.permissionOverwrites.edit(d.GuildID, { SEND_MESSAGES: null, }); await DB.deleteOne({ ChannelID: Channel.id }); }, ExpireDate); }); }); };

y aquí está el error que me sale:

 TypeError: Cannot read properties of undefined (reading 'channels')
about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

Existe la posibilidad de que no todos los canales y gremios se agreguen al caché. Intenta buscarlos primero y luego verás. Por ejemplo, algo como esto debería funcionar:

 const { Client } = require('discord.js'); const DB = require('../Structures/Schemas/LockDown'); /** * @param {Client} client */ module.exports = async(client) => { DB.find().then(async(documentsArray) => { documentsArray.forEach(async(d) => { const GuildChannel = await client.guilds.fetch(d.GuildId); const Channel = await GuildChannel.channels.fetch(d.ChannelID); if (!Channel) return; const TimeNow = Date.now(); if (d.Time < TimeNow) { Channel.permissionOverwrites.edit(d.GuildID, { SEND_MESSAGES: null, }); return await DB.deleteOne({ ChannelID: Channel.id }); } const ExpireDate = d.time - Date.now(); setTimeout(async() => { Channel.permissionOverwrites.edit(d.GuildID, { SEND_MESSAGES: null, }); await DB.deleteOne({ ChannelID: Channel.id }); }, ExpireDate); }); }); };

En lugar de obtener el gremio y luego el canal, obtenga directamente el canal del cliente de la siguiente manera:

 const { Client } = require('discord.js'); const DB = require('../Structures/Schemas/LockDown'); /** * @param {Client} client */ module.exports = async(client) => { DB.find().then(async(documentsArray) => { documentsArray.forEach(async(d) => { const Channel = await client.channels.fetch(d.ChannelID); if (!Channel) return; const TimeNow = Date.now(); if (d.Time < TimeNow) { Channel.permissionOverwrites.edit(d.GuildID, { SEND_MESSAGES: null, }); return await DB.deleteOne({ ChannelID: Channel.id }); } const ExpireDate = d.time - Date.now(); setTimeout(async() => { Channel.permissionOverwrites.edit(d.GuildID, { SEND_MESSAGES: null, }); await DB.deleteOne({ ChannelID: Channel.id }); }, ExpireDate); }); }); };

O, como dijo @Malik Lahlou , podría ser un error tipográfico.

Recursos:

  • ChannelManager.fetch()
  • GuildManager.fetch()


¡Esperaba que esto ayudara!

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!