Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

how to pull message data from discord.js?

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?

like image 907
Electro lemon Avatar asked Jan 29 '26 15:01

Electro lemon


1 Answers

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

like image 196
macdja38 Avatar answered Jan 31 '26 05:01

macdja38



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!