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

列出所有公會的用戶 ID (discord.js)

Listing user ids from all guilds (discord.js)(列出所有公會的用戶 ID (discord.js))
本文介紹了列出所有公會的用戶 ID (discord.js)的處理方法,對大家解決問題具有一定的參考價值,需要的朋友們下面隨著小編來一起學習吧!

問題描述

我知道此代碼中的某些元素可能已被棄用.但是,我找到了這段代碼,并在一定程度上對其進行了更改,但我收到了一個錯誤.我正在尋找所有公會中的用戶 ID,我知道您可能會受到所有公會中用戶數量的限制.

<塊引用>

TypeError: client.guilds.forEach 不是函數

//公會成員IDclient.on('消息', 消息 => {if (message.content === '$listmids') {if (message.author.id !== "651167823749578798") 返回;client.guilds.forEach(成員 => {console.log(`${member.id}`)var idserver = (`${member.id}`)//id 每個公會var memserver = client.guilds.get(idserver);//檢查公會idmemserver.members.forEach(成員 => {console.log(member.user.id);//console.log 查看該公會中的 id 用戶});//獲取所有公會的用戶 ID});}});

解決方案

你不需要獲取用戶,他們已經被緩存了.你不能使用

您還可以使用 websocket 事件 GUILD_CREATE 在機器人啟動時將所有用戶 ID 記錄到控制臺:

client.ws.on("GUILD_CREATE", (data) => {console.log(`列出來自公會'${data.name}'的用戶ID`);console.log(data.members.map(m => m.user.id));});


至于與discord.js 13.xx的兼容性,是完全兼容的,但是需要GUILDSintent來接收GUILD_CREATE網絡套接字.并且 GUILD_PRESENCES 意圖將用戶包含在公會數據中.

還有 GUILD_MESSAGES 以使命令正常工作.并為 messageCreate 而不是 message 偵聽 (client.on(...)),它已被棄用.

const client = new Discord.Client({ intents: ["GUILDS", "GUILD_MESSAGES", "GUILD_PRESENCES"] });

使用 discord.js ^12.5.3.

I'm aware that some of the elements in this code has probably been deprecated. However, I found this code and I have altered it to some extent but I am receiving a error. I'm looking to fetch user ids in all guilds, I understand that you can get ratelimited by the amount of users in all guilds.

TypeError: client.guilds.forEach is not a function

// guild member ids
client.on('message', message => {
    if (message.content === '$listmids') {
        if (message.author.id !== "651167823749578798") return;
        client.guilds.forEach(member => {
            console.log(`${member.id}`)

            var idserver = (`${member.id}`) // id each guild
            var memserver = client.guilds.get(idserver); // check guild with id

            memserver.members.forEach(member => {
                console.log(member.user.id); // console.log see id user in that guild
            }); // get userid all guild
        });
    }
});

解決方案

You don't need to fetch the users, they are already cached. You can't use GuildManager.fetch() nor UserManager.fetch() to fetch all the users or guilds, since it has an id (Twitter Snowflake) as a required parameter (referring to @MrMythical's answer).

When a discord bot is started an event GUILD_CREATE is emitted on the websocket for each guild. The client uses this to cache all the .guilds and .users, etc.

So you can simply use:

// An array of user ids
const users = client.users.cache.map(u => u.id);

To implement this in a command:

client.on("message", (message) => {

    if (message.author.id == client.user.id) return;

    if (message.content == "$listmids") {
        const users = client.users.cache.map(u => u.id);
        console.log(`Listing user ids from all guilds:`);
        console.log(users);
    }

});

You can also use the websocket event GUILD_CREATE to log all user ids to console on bot's startup:

client.ws.on("GUILD_CREATE", (data) => {
    console.log(`Listing user ids from a guild '${data.name}'`);
    console.log(data.members.map(m => m.user.id));
});


As for compatibility with discord.js 13.x.x, it is fully compatible, but you need GUILDS intent to receive GUILD_CREATE on the websocket. And GUILD_PRESENCES intent to include the users in the guild data.

Also GUILD_MESSAGES for the command to work. And listen (client.on(...)) for messageCreate instead of message, it is deprecated.

const client = new Discord.Client({ intents: ["GUILDS", "GUILD_MESSAGES", "GUILD_PRESENCES"] });

Using discord.js ^12.5.3.

這篇關于列出所有公會的用戶 ID (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 服務器時的歡迎消息)
主站蜘蛛池模板: 精品欧美一区二区中文字幕视频 | 久久av在线播放 | 亚洲一区二区av | 欧美视频精品 | 欧美一级一 | 午夜视频免费在线观看 | 99re在线视频 | 久久综合一区 | 久久精品国产亚洲夜色av网站 | 亚洲免费视频在线观看 | 国产精品久久一区二区三区 | 免费一区二区三区 | 国产成人免费视频网站视频社区 | 日韩在线精品强乱中文字幕 | 国产精品一区一区 | a在线视频 | 久久精品国产免费看久久精品 | 国产成人99久久亚洲综合精品 | 欧美理论| 中文字幕在线观看成人 | 手机在线一区二区三区 | 国产中文原创 | 99视频免费在线 | 久久九七| 午夜精品 | 亚洲一二三区在线观看 | www.精品国产| 91免费电影 | 中文字幕一区在线 | 久久综合久久久 | 国产精品成人一区二区 | 天天干天天干 | 伊人色综合久久天天五月婷 | aⅴ色国产 欧美 | 久草视 | 九九亚洲 | 欧美久久久久久久久 | 在线视频成人 | 紧缚调教一区二区三区视频 | 一区二区伦理电影 | 98久久|