Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
430 views
in Technique[技术] by (71.8m points)

javascript - 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
});

How I can see the members and server Icon of the added server?

question from:https://stackoverflow.com/questions/66068600/how-i-can-show-in-guildcreate-the-members-and-server-icon-on-discord-js

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

You can get the Guild's icon using the iconURL() method of Guild.

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

Getting the members of the Guild is pretty straightforward. You can use the memberCount property of Guild.

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

Since Guild.members.cache is a Collection, you can as well map the members by any property you'd like. (Id, username, discriminator, tag etc...)

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

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...