Tratando de obtener 10 mensajes de cada canal en un gremio y leer los contenidos y luego ver si contienen una determinada cadena, pero aparece el siguiente error
TypeError: Cannot read properties of undefined (reading 'fetch')este es mi codigo
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)) }) })interaction.guild.channels.cache es una colección de GuildChannel .
GuildChannels combina todas estas categorías de canales.
Lamentablemente, solo los canales de texto y los canales de noticias tienen una propiedad de messages .
Tal vez necesite verificar esta condición antes de obtener los mensajes.
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)) }) } })También puedes filtrar los canales.
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)) }) })