最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - Fetch messages with discord.js V12 doesn't work for me. [Discord.js V12] - Stack Overflow

programmeradmin1浏览0评论

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

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

Share Improve this question edited Mar 30, 2020 at 5:43 Choudini asked Mar 30, 2020 at 3:51 ChoudiniChoudini 931 silver badge7 bronze badges 3
  • Could you please explain what "doesn't work"? What do you expect to see? What are you actually seeing? Are there any reported error messages? – Phil Commented Mar 30, 2020 at 4:05
  • Yes sorry, I edited my topic. – Choudini Commented Mar 30, 2020 at 4:19
  • You shouldn't use the var keyword; prefer const and let instead. – ations Commented Apr 8, 2021 at 18:03
Add a ment  | 

2 Answers 2

Reset to default 3

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/#/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/#/docs/main/stable/class/Channel

发布评论

评论列表(0)

  1. 暂无评论