'Fetch messages with discord.js V12 doesn't work for me. [Discord.js V12]
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
Solution 1:[1]
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.
Solution 2:[2]
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
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
Solution | Source |
---|---|
Solution 1 | Choudini |
Solution 2 |