Reputation: 15
I've been looking everywhere for an explanation, even reading the discord.js docs but nothing. Does anyone know how to react to a specific user id's message in discord.js?
Upvotes: 0
Views: 66
Reputation: 8412
You can get any message through the MessageManager.cache
, or using MessageManager.fetch()
if the message is not cached. Fetching the message is a lot more restricting since you can only fetch the last 100 messages in the channel.
From there, you can find
/filter
the message(s) you want by looking at their author
property.
// <channel> is a placeholder for the channel object you'd like to search
// get every cached message by a user in one channel
<channel>.messages.cache.filter(({ author }) => author.id === 'ID Here')
<channel>.messages.fetch({ limit: 100 }).then((messages) => {
// same thing, but with uncached messages
messages.filter(({ author }) => author.id === 'ID Here');
Each GuildMember
also has a lastMessage
property if that could come in handy for you.
// <guild> is a placeholder for the guild object you'd like to search
// get the user's last message
guild.member('ID Here').lastMessage;
Upvotes: 1