久久久久久久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 服務器時的歡迎消息)
主站蜘蛛池模板: 国产精品一区二区久久精品爱微奶 | 欧美综合一区 | 国产探花在线精品一区二区 | 色橹橹欧美在线观看视频高清 | 中文字幕在线第二页 | 欧美精品第一区 | 欧美日韩在线视频一区 | 91精品国产综合久久婷婷香蕉 | 天天操天天舔 | 成人国产精品免费观看 | 亚洲www啪成人一区二区麻豆 | 亚洲精品在线视频 | 亚洲 中文 欧美 日韩 在线观看 | 91精品国产91久久久 | 国产在线播放一区二区三区 | 国产亚洲成av人在线观看导航 | 91在线网站 | 婷婷在线免费 | 国产成人免费在线 | 91精品久久久久久久久久 | 久久大 | 国产视频中文字幕 | 亚洲在线成人 | 中文字幕国产 | 一区二区久久精品 | 黄色片视频网站 | 亚洲一区二区视频在线播放 | 欧美成人综合 | 亚洲国产精品视频 | 操皮视频 | 天天色官网 | 福利社午夜影院 | 91精品国产91久久久久久密臀 | 色婷婷久久综合 | 国产高清免费视频 | 久久一热 | 亚洲一区二区视频在线观看 | 久久九九影视 | 日韩国产中文字幕 | 国产精品不卡 | 在线中文视频 |