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

Discord.js 獲取兩個用戶之間的公共服務器

Discord.js Get common servers between two users(Discord.js 獲取兩個用戶之間的公共服務器)
本文介紹了Discord.js 獲取兩個用戶之間的公共服務器的處理方法,對大家解決問題具有一定的參考價值,需要的朋友們下面隨著小編來一起學習吧!

問題描述

我正在尋找兩個不和諧 User 之間的公共服務器.目前,我的機器人能夠訪問它所屬的公會,但是給定一個向它發送消息的用戶,它無法訪問該用戶的任何公會.我知道不和諧會限制您查看共享的公會/服務器,但我什至找不到任何訪問這些的方法.

I am looking to get the common servers between two discord Users. Currently, my bot is able to access the guilds that it is a part of, however given a user who has sent it a message, it is unable to access any of the guilds of the user. I understand that discord limits you to seeing shared guilds/servers, but I can't find any way to even access those.

任何幫助將不勝感激.

上下文:DM

guild = message.client.guilds.cache.find(clientGuild=>message.author.????)

我想要類似的東西:

guild = message.client.guilds.cache.find(clientGuild=>message.author.guilds.includes(clientGuild)

推薦答案

這不適用于分片.我還沒有分片的經驗,所以我會把它留給有經驗的人.

This will not work with sharding. I don't have experience with sharding yet, so I'll leave it for someone else with experience.

您可以嘗試使用緩存的成員(并祈禱用戶被緩存,如果用戶發送了消息但不能保證會出現這種情況)或獲取成員.

You can either try to use the cached members (and pray that the user is cached, which should be the case if the user sent a message but isn't guaranteed) or fetch the member.

公會對象有一個成員 從用戶獲取成員對象的方法.您可以簡單地檢查它是否未定義以查看用戶是否在公會中并且被緩存.

The guild object has a member method to get the member object from user. You can simply check that it's not undefined to see if the user is in the guild and is cached.

client.guilds.cache.filter(guild => !!guild.member(message.author));

使用 fetch 的更長方法

這將獲取成員,因此具有高公會計數的機器人可能會達到速率限制(查看文檔 這里).

var guilds = Promise.all(
    client.guilds.cache.map(async guild => [
        guild.id,
        await guild.members.fetch(message.author).catch(() => null))
    ])
).then(guilds => guilds.filter(g => g[1]).map(guild => client.guilds.resolve(guild[0]));

它通過嘗試從機器人所在的每個公會中獲取成員來工作(fetch 可能會失敗,所以有一個只返回 null 的 catch),然后根據結果過濾公會.collection 類上沒有異步過濾器,所以我改為映射到異步謂詞,然后我使用 等待它們Promise.all.

It works by trying to fetch the member from every guild the bot is in (the fetch may fail so there's a catch which just returns null) and then filtering the guilds based on the result. There's no async filter on the collection class, so instead I map to async predicates which I then await them using Promise.all.

如果你需要分片,應該可以使用broadcastEval做同樣的事情,但是我還沒有足夠的信心來寫它.

If you need sharding, it should be possible to do the same using broadcastEval, but I'm not confident enough to write it yet.

這篇關于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 服務器時的歡迎消息)
主站蜘蛛池模板: 波多野结衣中文视频 | 一级在线观看 | 亚洲国产乱码 | 99精品久久 | 国产一区二| 国产一区三区视频 | 精品视频一区二区 | 久草资源网站 | 午夜视频网站 | 国产视频久久久 | 福利社午夜影院 | 黑人巨大精品 | 日韩av成人在线观看 | 日韩视频在线一区二区 | 国产精品网址 | 成人小视频在线观看 | 成人影院午夜 | 欧美成人激情 | 午夜在线影院 | 欧美成人a| 日韩精品一区二区三区视频播放 | 日韩中文字幕视频在线观看 | 国产乱码精品1区2区3区 | 久久久久久91| 日韩欧美在线一区 | 日韩av在线一区 | 日韩一区二区在线视频 | 日本三级做a全过程在线观看 | 亚洲精品一区在线 | 在线视频 欧美日韩 | 欧美一区二区三区一在线观看 | 久久极品 | www.黄网| 国产精品久久久久久久7777 | 久久国产一区 | 久久激情网 | www.日日夜夜 | 欧美日日日日bbbbb视频 | 午夜99| 美女毛片免费看 | 国产精品久久久久久久久图文区 |