An error occurred while trying to fetch the channels: TypeError: Cannot read properties of undefined (reading 'messages') at file:///C:/Users/Administrator/Desktop/gb-ac-bot/src/utils.js:7:88 at Array.map (<anonymous>) at Object.allMessagesFromChannelList (file:///C:/Users/Administrator/Desktop/gb-ac-bot/src/utils.js:7:53) at Object.updateServerInfo (file:///C:/Users/Administrator/Desktop/gb-ac-bot/src/scheduler.js:6:34) at Timeout._onTimeout (file:///C:/Users/Administrator/Desktop/gb-ac-bot/src/index.js:53:21) at listOnTimeout (node:internal/timers:559:17) at processTimers (node:internal/timers:502:7)
const allMessagesFromChannelList = async (client) => { const channels = global.channels.map(id => client.channels.cache.get(id)) try { const messages = await Promise.all(channels.map(async channel => await channel.messages.fetch({ limit: 50 }))) return messages.map(collection => collection.map(value => value)) .flat() .filter(msg => msg.author.id === global.botId) } catch (error) { console.error('An error occurred while trying to fetch the channels: ', error) return [] } }
const messages = await Promise.all(channels.map(async channel => await channel.messages.fetch({ limit: 50 })))
Promise
channels
map()
channel
channel.messages
var
This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)