【问题标题】:Reacting to a specific user ID with an emoji in discord.js在 discord.js 中使用表情符号对特定用户 ID 做出反应
【发布时间】:2021-02-06 10:58:39
【问题描述】:

我一直在到处寻找解释,甚至阅读了 discord.js 文档,但一无所获。有谁知道如何对 discord.js 中特定用户 ID 的消息做出反应?

【问题讨论】:

    标签: javascript node.js discord discord.js


    【解决方案1】:

    您可以通过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;
    

    【讨论】:

      猜你喜欢
      • 2020-11-14
      • 2021-08-11
      • 1970-01-01
      • 2019-02-03
      • 2021-12-17
      • 2018-08-18
      • 2021-07-15
      • 2021-05-20
      • 1970-01-01
      相关资源
      最近更新 更多