E
E
exetico2020-11-24 00:14:50
Node.js
exetico, 2020-11-24 00:14:50

How to get all messages from a discord channel?

I need to get all the messages that are on the channel when requesting a discord bot from my site.
Those. we send a request to my server, on the server the discord bot is already connected to the discord server (there is a server id, a channel id), then my server should return an array with all messages to me.
No matter how much I google, I can’t find it, for documentation my English is really bad

Answer the question

In order to leave comments, you need to log in

1 answer(s)
A
Alexander, 2020-11-24
@exetico

use the .fetch() method :

message.channel.messages.fetch({
  limit: 100 // количество сообщений 
}).then(async messages => {
  let finalArray = [];

  const putInArray = async (data) => finalArray.push(data);

  for (const message of messages.array().reverse()) await putInArray(`${message.content}`);

  console.log(finalArray); // ['value1', 'value2', 'valueN']

});

I don’t advise you to get too carried away with this, it will affect the performance of the bot, so always assign a value to the limit.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question