BeginnerDiscord

Discord Server Stats

Fetch live member counts and online presence from your Discord server.

Click to expand
Flow StartAPI GETHTTP RequestDiscord APICodecodeJsSimple OutputStats JSON

Discord Server Stats

Fetch live member counts and online presence from your Discord server via the Discord API.

Overview

This workflow exposes an API endpoint that queries the Discord API for your server's guild info - total members, online count, server name, and number of roles. It's useful for displaying live community stats on your website or dashboard.

Prerequisites

  • A Discord application with a bot added to your server
  • The bot token (from the Discord Developer Portal → Bot → Token)
  • Your Discord server (guild) ID
  • The bot must have the SERVER MEMBERS INTENT enabled

What You'll Build

A single API endpoint that:

  • Calls the Discord API to fetch guild info with member counts
  • Extracts total members, online members, server name, and role count
  • Returns a clean JSON response

Endpoint: GET /api/v1/YOUR_ID/servercount

Response:

{
  "members": 1250,
  "online": 342,
  "name": "My Server",
  "roles": 15
}

Workflow Nodes

1. Flow Start - API Endpoint

Setting Value
Trigger Type API
Method GET
Custom Path servercount
Rate Limit 60
Timeout 30

You can also allow POST if you want to call this from a frontend form or webhook.

2. HTTP Request - Discord API

Calls the Discord REST API to get guild information including approximate member and presence counts.

Setting Value
Method GET
URL https://discord.com/api/v10/guilds/YOUR_GUILD_ID?with_counts=true

Headers:

Key Value
Content-Type application/json
Authorization Bot YOUR_BOT_TOKEN

Output variable: httpRequest

The ?with_counts=true query parameter is required - without it, the API won't return approximate_member_count and approximate_presence_count.

3. Code - Extract Stats

Parses the Discord API response and extracts the fields we need.

Output variable: codeJs

var guild = variables.httpRequest.data;
var result = {
  members: guild.approximate_member_count,
  online: guild.approximate_presence_count,
  name: guild.name,
  roles: guild.roles.length
};
result;

Discord API Response Fields

The guild object from Discord contains many fields. Here are the ones we use:

Field Type Description
approximate_member_count number Total members in the server
approximate_presence_count number Members currently online
name string Server name
roles array List of server roles

4. Simple Output - Return Stats

Returns the extracted stats as JSON.

Setting Value
Status 200
Type JSON
Output {{codeJs}}

Getting Your Guild ID

  1. Open Discord and go to User Settings → Advanced
  2. Enable Developer Mode
  3. Right-click your server name in the sidebar
  4. Click Copy Server ID

Getting Your Bot Token

  1. Go to the Discord Developer Portal
  2. Select your application → Bot
  3. Click Reset Token (or copy if visible)
  4. Use it as Bot YOUR_BOT_TOKEN in the Authorization header

Never share your bot token publicly. If it leaks, reset it immediately from the Developer Portal.

CORS Configuration

If you're calling this endpoint from a frontend app, add your domain to the CORS origins in the Flow Start settings:

https://yourdomain.com

Testing

Using curl

curl "https://your-domain.com/api/v1/YOUR_ID/servercount"

Expected:

{
  "members": 1250,
  "online": 342,
  "name": "My Server",
  "roles": 15
}

What to verify

Check Expected
members Total server members (number)
online Currently online members (number)
name Your Discord server name
roles Number of roles in the server

If you get an error, check that your bot token is valid and the bot has been added to the server. The bot needs to be a member of the guild to query its info.

Security Checklist

Control Status
Bot token authentication (Authorization header)
Rate limiting (60/min)
Read-only endpoint (no data mutations)
CORS configurable in Flow Start
No real secrets in tutorial JSON