Utility
Server info
Embed utility command
Shows member count, channel count, and creation date in an embed — a common utility command pattern.
Based on discord.js guide — embeds
/serverinfo
Source preview
import {
Client,
Events,
GatewayIntentBits,
REST,
Routes,
SlashCommandBuilder,
EmbedBuilder,
MessageFlags,
} from "discord.js";
const client = new Client({ intents: [GatewayIntentBits.Guilds] });
const commands = [
new SlashCommandBuilder()
.setName("serverinfo")
.setDescription("Show basic server stats"),
].map((c) => c.toJSON());
client.once(Events.ClientReady, async () => {
const rest = new REST({ version: "10" }).setToken(process.env.DISCORD_TOKEN!);
await rest.put(Routes.applicationCommands(client.user!.id), { body: commands });
});
client.on(Events.InteractionCreate, async (interaction) => {
if (!interaction.isChatInputCommand() || interaction.commandName !== "serverinfo") return;
const guild = interaction.guild;
if (!guild) {
await interaction.reply({ content: "Guild only.", flags: MessageFlags.Ephemeral });
return;
}
const embed = new EmbedBuilder()
.setTitle(guild.name)
.addFields(
{ name: "Members", value: String(guild.memberCount), inline: true },
{ name: "Channels", value: String(guild.channels.cache.size), inline: true },
{ name: "Created", value: guild.createdAt.toDateString(), inline: true },
)
.setColor(0x7c3aed);
await interaction.reply({ embeds: [embed] });
});
client.login(process.env.DISCORD_TOKEN);