As you can read on my title, I can't fetch messages with discord.js.
In discord.js v11 I used this :
var bot = new Discord.Client();
bot.on('ready', () => {
bot.channels.get(channelID).fetchMessages({ around: messageID, limit: 1 })
.then(async msg => {
//my code here
});
});
Id discord.js v12 it should be like this :
var bot = new Discord.Client();
bot.on('ready', () => {
bot.channels.cache.get(channelID).messages.fetch({ around: messageID, limit: 1 })
.then(async msg => {
//my code here
});
});
But it doesn't work for me..
Can you please help me for this ? May be with an other alternative.
Thank you for your help !
EDIT 1 :
It return :
(node:17184) UnhandledPromiseRejectionWarning: TypeError: Cannot read property 'messages' of undefined
Well, I'm sorry, I figure it out that my code was correct, but I do not know why that doesn't worked when I tried it .. I literally wrote this:
bot.channels.cache.get('ChannelID').messages.fetch({ around: 'messageID', limit: 1 })
.then(async msg => {
//my code here
})
That's the same shit, I lost hours for that '-'
Anyway, sorry for the lost of your time to.
I'll delete this.
discord.js v12 doesnt use client.channels.cache.get(id)
but client.channels.resolve(id)
https://discord.js.org/#/docs/main/stable/class/ChannelManager?scrollTo=resolve
I don't quite understand what you mean by messages property, as channel doesnt have any like that in documentation. https://discord.js.org/#/docs/main/stable/class/Channel
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With