为了账号安全,请及时绑定邮箱和手机立即绑定

在 discord.js 中使用表情符号对特定用户 ID 做出反应

在 discord.js 中使用表情符号对特定用户 ID 做出反应

江户川乱折腾 2023-06-09 15:48:53
我一直在到处寻找解释,甚至阅读了 discord.js 文档,但一无所获。有谁知道如何在 discord.js 中对特定用户 ID 的消息做出反应?
查看完整描述

1 回答

?
慕桂英3389331

TA贡献2036条经验 获得超8个赞

您可以通过 获取任何消息,如果消息未被缓存,MessageManager.cache则使用。MessageManager.fetch()获取消息的限制要多得多,因为您只能获取频道中的最后 100 条消息。

从那里,您可以find/filter通过查看他们的属性来获得您想要的消息author

// <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;


查看完整回答
反对 回复 2023-06-09
  • 1 回答
  • 0 关注
  • 75 浏览
慕课专栏
更多

添加回答

举报

0/150
提交
取消
意见反馈 帮助中心 APP下载
官方微信