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

javascript - Discord.js: Fetch message from ALL channels - Stack Overflow

programmeradmin1浏览0评论

message.channel.messages.fetch does fine at fetching from the channel the mand is run in, but I need to be able to fetch messages from ANY channel in the server. For reference, I'm making a mand to quote a message via message ID, but as of right now it can only quote messages from the same channel that the mand is run in.

message.channel.messages.fetch does fine at fetching from the channel the mand is run in, but I need to be able to fetch messages from ANY channel in the server. For reference, I'm making a mand to quote a message via message ID, but as of right now it can only quote messages from the same channel that the mand is run in.

Share Improve this question asked Jun 12, 2020 at 16:22 SomnaSomna 281 gold badge1 silver badge8 bronze badges
Add a ment  | 

2 Answers 2

Reset to default 1

Loop through every channel and fetch messages in them.

message.guild.channels.cache.forEach(channel => {
  channel.messages.fetch().then(messages => {
    messages.forEach(msg => console.log(msg.content));
  });
});

This example fetches as many messages as possible from every channel in the server and logs the content of each one. You could use an if statement to check if the message content is the specified quote to look for.

MessageManager.fetch()

let found;

message.guild.channels.cache.each(channel => {
   if(found) return;
   found = await channel.messages.fetch("ID_HERE").catch(() => undefined);
});
发布评论

评论列表(0)

  1. 暂无评论