簡體   English   中英

我如何在公會中顯示 discord.js 上的成員和服務器圖標

[英]How I can show in guildCreate the members and server Icon on discord.js

client.on("guildCreate", (guild) => {
    console.log(`I'm added in ${guild.name}`); //log console
    const embed = new MessageEmbed() //The embed//the embed
        .setAuthor("I'm in a new server!") //the author message
        .addField("server name", `${guild.name}`) //the name
        .setColor("GREEN") //the colour
        .addField("Actual servers", `${client.guilds.cache.size}`); //the actual servers
    client.channels.cache.get("779832833320681515").send(embed); //the channel of the embed
});

如何查看添加的服務器的成員和服務器圖標?

公會#iconURL()

將公會的圖標 URL 作為字符串返回。

client.on('guildCreate', guild => {
  console.log(guild.iconURL())
})

GuildMemberManager#cache

返回所有緩存的公會成員的集合

client.on('guildCreate', guild => {
  console.log(guild.members.cache)
  // Keep in mind: This will quite literally spam your terminal.
})

您可以使用 Guild 的iconURL()方法獲取Guild的圖標。

client.on("guildCreate", guild => {
    console.log(guild.iconURL({dynamic: true, size: 2048}));
});

獲得公會成員非常簡單。 您可以使用GuildmemberCount屬性。

client.on("guildCreate", guild => {
    console.log(guild.memberCount);
});

由於Guild.members.cache是一個Collection ,您也可以通過您想要的任何屬性map成員。 (ID、用戶名、鑒別器、標簽等...)

client.on("guildCreate", guild => {
    console.log(guild.members.cache.map(member => member.user.tag));
    // --> ["Wumpus#0000", "entrynidy#1234"]
});

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM