Reputation: 19
How can I cache messages in discord.js? I wanted to make a reaction roles system, but the event for adding reactions works only for cached messages. I put this code in the "ready" function:
bot.channels.cache.get(channel id).messages.cache.get(message id)
This does not work, the event still does not fire. Am I doing something wrong?
Upvotes: 1
Views: 649
Reputation: 8412
You can forcefully cache messages through MessageManager#fetch
.
// with promises
bot.channels.cache
.get('channel id')
.messages.fetch('message id')
.then(() => {
console.log(`The message has been cached`);
});
// with async/await (make sure your function is async)
await bot.channels.cache.get('channel id').messages.fetch('message id');
console.log(`The message has been cached`);
Upvotes: 2