Reputation: 1394
Here is my code
import Discord from 'discord.js'
const bot = new Discord.Client()
const channelID = 'the channel's id'
bot.login('my token')
bot.on('ready', async () => {
const channel = (await bot.channels.fetch(channelID)) as Discord.TextChannel //im using typescript
console.log(channel.messages.cache.array())
})
For some reason the array is empty, even though there are tons of messages in the channel. Any reason this might be? I know that it is getting the right channel, as I've tested that and it shows the right server and name. Thanks.
Upvotes: 0
Views: 716
Reputation: 5174
Use channel.messages.fetch().array()
instead. Your array is most likely empty because the messages are not cached, optionally you can also cache the messages by doing channel.messages.fetch({}, true).array()
Upvotes: 2