how to pull message data from discord.js?

18,232

For those using discord.js v8 or lower.

If you want to pull all the message objects from the channel I recomend ignoring the cach and instead using getChannelLogs(channel, limit, options, callback) Which will allow you to fetch up to 100 messages at once, but those messages do not have to be cached within discord.js. You can quite easily create a recursive function that on the callback fetches more messages to fetch as many messages as you want.

That said server.channel.messages will be all of the messages in it that discord.js has cached. If it appears empty chances are no-one sent a message since the bot was activated.

source: http://discordjs.readthedocs.io/en/latest/docs_client.html#getchannellogs-channel-limit-options-callback

Share:
18,232
Electro lemon
Author by

Electro lemon

Updated on June 05, 2022

Comments

  • Electro lemon
    Electro lemon almost 2 years

    Discord.js is an API for Discord that allows the developers to make plugins for the program, discord. here's the link to the API code it's in js, https://github.com/hydrabolt/discord.js/

    Discord is setup to be like a server where you connect and chat on channels, my problem is how do I pull the message data from the channels.

    What they did is setup all the channels in a JSON cache and within the channel, objects is another cache with the messages objects(what documentation says). But when I get to the message cache all I see is messages: Cache { limit: 1000 } }. How do I pull all the message objects from the channel?