Using the new prefix endpoint trigger, you can retreive informations about your server easily! Make sure you have turned on server members intent so you could list the members and bots in the servers too!
// authenticates you with the API standard library
// type `await lib.` to display API autocomplete
const lib = require('lib')({token: process.env.STDLIB_SECRET_TOKEN});
let guild = await lib.discord.guilds['@0.1.0'].retrieve({ //retrieves all the available informations of the server. there is so much more you can do with the info than just server information!
guild_id: `${context.params.event.guild_id}`,
with_counts: true,
});
let roles = await lib.discord.guilds['@0.0.6'].roles.list({ //lists all the roles in the server
guild_id: context.params.event.guild_id,
});
let channels = await lib.discord.guilds['@0.1.1'].channels.list({ //lists all the channels in the server
guild_id: context.params.event.guild_id,
});
let members = await lib.discord.guilds['@0.0.6'].members.list({ //used to list members in the server
guild_id: `${context.params.event.guild_id}`,
limit: 1000,
});
let botmembers = members.filter((x) => x.user.bot); //filter out bots from the server member list
let ServerIconCheck = await lib.http.request['@1.1.5']({ //checks if there is a server icon with http request of GET method.
method: 'GET',
url: `https://cdn.discordapp.com/icons/${context.params.event.guild_id}/${guild.icon}.png`
});
if (ServerIconCheck.statusCode !== 200) { //if http request did not return status code 200 indicating ok, that means there is no server icon. So, show a default icon.
let serverIcon = `https://cdn.discordapp.com/attachments/904664337178824785/904670053679661076/png-clipart-discord-computer-icons-online-chat-cool-discord-icon-logo-smiley-thumbnail.png`;
await lib.discord.channels['@0.2.0'].messages.create({
channel_id: `${context.params.event.channel_id}`,
content: `<@!${context.params.event.author.id}>, here is your server information!`,
tts: false,
embeds: [
{
type: 'rich',
title: '',
description: '',
color: 0x00ffff,
fields: [
{
name: `Overview`,
value: `Server Owner: <@!${guild.owner_id}>\nServer Boost Status: \`${guild.premium_subscription_count}/14\`\nServer Boost Tier: \`${guild.premium_tier}\`\nServer Region: \`${guild.region}\``,
inline: true,
},
{
name: `Other`,
value: `Member Count: \`${guild.approximate_member_count}\`\nBot Count: \`${botmembers.length}\`\nRole Count: \`${roles.length}\`\nCategory and Channels Count: \`${channels.length}\``,
inline: true,
},
],
author: {
name: `${guild.name}`,
icon_url: `${serverIcon}`,
},
},
],
});
}
else{ //otherwise, if there is a server icon, trigger this code instead.
await lib.discord.channels['@0.2.0'].messages.create({
channel_id: `${context.params.event.channel_id}`,
content: `<@!${context.params.event.author.id}>, here is your server information!`,
tts: false,
embeds: [
{
type: 'rich',
title: '',
description: '',
color: 0x00ffff,
fields: [
{
name: `Overview`,
value: `Server Owner: <@!${guild.owner_id}>\nServer Boost Status: \`${guild.premium_subscription_count}/14\`\nServer Boost Tier: \`${guild.premium_tier}\`\nServer Region: \`${guild.region}\``,
inline: true,
},
{
name: `Other`,
value: `Member Count: \`${guild.approximate_member_count}\`\nBot Count: \`${botmembers.length}\`\nRole Count: \`${roles.length}\`\nCategory and Channels Count: \`${channels.length}\``,
inline: true,
},
],
author: {
name: `${guild.name}`, //the guild's name
icon_url: `${guild.icon_url}`, //the server icon URL
},
},
],
});
}