【发布时间】:2021-02-06 10:58:39
【问题描述】:
我一直在到处寻找解释,甚至阅读了 discord.js 文档,但一无所获。有谁知道如何对 discord.js 中特定用户 ID 的消息做出反应?
【问题讨论】:
标签: javascript node.js discord discord.js
我一直在到处寻找解释,甚至阅读了 discord.js 文档,但一无所获。有谁知道如何对 discord.js 中特定用户 ID 的消息做出反应?
【问题讨论】:
标签: javascript node.js discord discord.js
您可以通过MessageManager.cache 获取任何消息,如果消息未缓存,则使用MessageManager.fetch()。获取消息的限制要大得多,因为您只能获取频道中的最后 100 条消息。
从那里,您可以通过查看他们的author 属性来find/filter 想要的消息。
// <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');
每个GuildMember 也有一个lastMessage 属性,如果这对您有用的话。
// <guild> is a placeholder for the guild object you'd like to search
// get the user's last message
guild.member('ID Here').lastMessage;
【讨论】: