久久久久久久av_日韩在线中文_看一级毛片视频_日本精品二区_成人深夜福利视频_武道仙尊动漫在线观看

Discord.js - 讓用戶最后一次活動?

Discord.js - Getting users last activity?(Discord.js - 讓用戶最后一次活動?)
本文介紹了Discord.js - 讓用戶最后一次活動?的處理方法,對大家解決問題具有一定的參考價值,需要的朋友們下面隨著小編來一起學習吧!

問題描述

我正在嘗試找出是否可以使用 discord.js

I'm trying to find out if its possible to get the time/information of users last activity retrospectively using discord.js

說我有類似的東西

  client.guilds.find('id', 'SERVER ID').fetchMembers().then(members => {
        const role = members.roles.find('name', 'Newbies')

        role.members.forEach(member => {
              console.log(member.user.lastMessage) // null
        })
  })

除非會員已經發帖,因為客戶端在監聽,所以lastMessage始終為null.

Unless the member has posted, since the client is listening, the lastMessage is always null.

有沒有辦法找到最后一個活動?還是一種解決方法,例如返回所有用戶消息的查詢,然后我可以從中獲取最新消息?

Is there a way to find the last activity? or a workaround, like a query to return all the users messages, which I can then take the most recent one from?

實際上,我想知道用戶上次發布的日期/時間,以便我們可以監控非貢獻帳戶.

Effectively I want to know what date/time the user last posted so we can monitor non-contributing accounts.

謝謝

推薦答案

查看文檔后,我也沒有找到任何東西,所以我想出了一個手動搜索功能.

After looking thought the documentation I didn't find something neither so I came up with a manual search function.

基本上,它會掃描每個頻道,直到找到來自 X 用戶的消息,或者頻道中的消息結束.然后它會比較來自每個渠道的用戶的最后一條消息并打印最后一條.

Basically, it will scan every channels until finding a message from X user, or the end of the messages in the channel. It then compare the last messages of the users from every channels and print the last one.

如果用戶很久沒有寫,它可能會很長.當然,您必須在嘗試之前檢查 lastMessage.

It can be very long if the user hasn't write since a long time. Of course, you have to check lastMessage before trying this.

我可能會添加一個時間限制.因為如果您有數千條消息,該函數將永遠運行.

I would add a time limit maybe. Because if you have thousand of messages, the function will run eternally.

如果找到的最后一條消息在接受的時間內不被踢/做任何事情,您可以停止該功能.

You can stop the function if the last message found is in the accepted time to not be kick/do whatever.

如果在 fetched messaged 包中找到的第一條消息超過了封禁限制,我就停止了搜索,但是,如果第一條消息不舊,請記住它意味著另一個,所以我們仍然需要檢查它們(也可以通過檢查包的最后一條消息來避免).

I made the search stop if the first message found in the pack of fetched messaged is older than the ban limit, however, if the first message is not older, remember that it means for the other, so we still need to check them (it can be avoided by checking the last message of the pack as well).

async function fetchMessageUser(chan, id, res) {
  let option = {};
  if (typeof res !== 'undefined'){
    option = {before: res.id};
  }
  return await chan.fetchMessages(option)
      .then(async msgs => {
    if (msgs.size === 0){
      return {continue: false, found: false};
    };
    if ((Date.now() - (msgs.first().createdTimestamp)) > 86400000 ) { // 1 day
      return {continue: false, found: false};
    }
    let msgByAuthor = msgs.find(msg => {
      return msg.author.id === id;
    });
    if (msgByAuthor === null){
      return {continue: true, id: msgs.last().id};
    } else {
      return {continue: false, found: true, timestamp: msgByAuthor.createdTimestamp};
    }
      })
      .catch(err => console.log('ERR>>', err));
}


client.on('message', async (msg) => {
  let timestamp = [];
  for (let [id, chan] of msg.guild.channels){
    if (chan.type !== 'text'){ continue; }
    let id = '587692527826763788'; // id of the user, here a non verified account
    let res;
    do {
      res = await fetchMessageUser(chan, id, res);
    } while(res.continue);
    if (res.found) {
      timestamp.push(res.timestamp);
    }
  }
  console.log(timestamp);
  let first = timestamp.sort((a,b) => (b-a))[0];
  console.log(new Date(first));
});

更好的變體是為一組用戶運行它,檢查來自每個頻道的所有 50 條最新消息,如果他寫了一條,則將每個用戶與他最近的消息相關聯,并這樣做直到所有消息中的所有消息頻道太舊,無法避免踢/無論如何.然后為所有沒有關聯消息的用戶做一些事情.

A better variant would be to run it for an array of users, checking all 50 last messages from every channel, and associating each users with his most recent messages if he wrote one, and doing this until all the messages in all the channels are too old to avoid a kick/whatever. And then do something for all the users who don't have an associated messages.

這篇關于Discord.js - 讓用戶最后一次活動?的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網!

【網站聲明】本站部分內容來源于互聯網,旨在幫助大家更快的解決問題,如果有圖片或者內容侵犯了您的權益,請聯系我們刪除處理,感謝您的支持!

相關文檔推薦

discord.js v12: How do I await for messages in a DM channel?(discord.js v12:我如何等待 DM 頻道中的消息?)
how to make my bot mention the person who gave that bot command(如何讓我的機器人提及發出該機器人命令的人)
How to fix Must use import to load ES Module discord.js(如何修復必須使用導入來加載 ES 模塊 discord.js)
How to list all members from a specific server?(如何列出來自特定服務器的所有成員?)
Discord bot: Fix ‘FFMPEG not found’(Discord bot:修復“找不到 FFMPEG)
Welcome message when joining discord Server using discord.js(使用 discord.js 加入 discord 服務器時的歡迎消息)
主站蜘蛛池模板: 天堂网中文字幕在线观看 | 国产一区二区在线视频 | 毛片网站免费观看 | 亚洲视频在线免费观看 | 婷婷五月色综合 | 欧美久久久久久 | 国产精品亚洲一区二区三区在线观看 | 三级黄视频在线观看 | 在线视频 中文字幕 | 日韩中文字幕免费在线 | 色屁屁在线观看 | 亚洲欧美日韩系列 | 欧美一级片在线看 | 在线看一区二区三区 | 午夜一区 | 狠狠久久 | 成人一级片在线观看 | 欧美亚洲综合久久 | 免费精品视频一区 | 日韩精品a在线观看图片 | 国产精品日韩一区二区 | 国产精品久久久久久中文字 | 国产高清在线精品一区二区三区 | 欧美日韩一二三区 | 国产精品黄 | 欧美aaaa视频 | 香蕉视频一区二区 | 一区二区三区日韩精品 | 成人免费网站 | 亚洲国产免费 | 中文字幕国产在线 | 福利一区二区 | 91福利在线导航 | 久久久www成人免费无遮挡大片 | 亚洲国产精选 | 91 视频网站 | 黄色网址在线免费观看 | 亚洲免费网址 | 日韩精品色网 | 久久久久久中文字幕 | 日本成人午夜影院 |