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

228
Vistas
TypeError: Cannot read properties of undefined (reading 'fetch') Discord.js v13

Trying to get 10 messages from every channel in a guild and read the contents then see if they contain a certain string but getting the error below

TypeError: Cannot read properties of undefined (reading 'fetch')

This is my code

interaction.guild.channels.cache.forEach(c => {
   c.messages.fetch({limit: 10}).then(msgs => {
      msgs.forEach(m => {
         if (m.content.includes(interaction.options.getString('text',true))) {
            // will do stuff here
         }
      }).catch(err => console.error(err))
   })
})
about 4 years ago · Juan Pablo Isaza
1 Respuestas
Responde la pregunta

0

interaction.guild.channels.cache is a collection of GuildChannel.

GuildChannels combines all theses categories of channels.

channels

Unfortunately, only Text Channels and News Channels have a messages property.

Maybe you need to check this condition before fetch the messages.

interaction.guild.channels.cache.forEach(c => {
   if(c.type == 'GUILD_TEXT'){
      c.messages.fetch({limit: 10}).then(msgs => {
         msgs.forEach(m => {
            if (m.content.includes(interaction.options.getString('text',true))) {
               // will do stuff here
            }
         }).catch(err => console.error(err))
      })
   }
})

You can also filter the channels

interaction.guild.channels.cache.filter((c) => c.type == 'GUILD_TEXT').forEach(c => {
   c.messages.fetch({limit: 10}).then(msgs => {
      msgs.forEach(m => {
         if (m.content.includes(interaction.options.getString('text',true))) {
            // will do stuff here
         }
      }).catch(err => console.error(err))
   })
})
about 4 years ago · Juan Pablo Isaza Denunciar
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