Discord Server Member Count Web Component

Test this app for free
99
import requests
from fastapi import FastAPI
from fastapi.responses import HTMLResponse

app = FastAPI()


def get_discord_server_member_count(server_id: str, bot_token: str) -> int:
    url = f"https://discord.com/api/v10/guilds/{server_id}/members?limit=1"
    headers = {"Authorization": f"Bot {bot_token}"}
    response = requests.get(url, headers=headers)
    response.raise_for_status()
    member_count = int(response.headers["x-total-count"])
    return member_count


# TODO: Replace with your Discord server ID and bot token
server_id = "YOUR_DISCORD_SERVER_ID"
bot_token = "YOUR_DISCORD_BOT_TOKEN"


@app.get("/member_count")
def member_count():
    count = get_discord_server_member_count(server_id, bot_token)
Get full code

Discord Server Member Count Web Component

Created: | Last Updated:

A web component that displays the member count of a Discord server and can be embedded in a Webflow website. The member count is fetched from an API endpoint, and the web component is served through another API endpoint.

Introduction to the Discord Server Member Count Web Component Template

Welcome to the step-by-step guide on how to use the Discord Server Member Count Web Component template. This template allows you to display the member count of a Discord server on your website. It fetches the member count from an API endpoint and serves the web component through another API endpoint. To get started, simply click "Start with this Template" on the Lazy platform.

Setting Environment Secrets

Before you can use this template, you need to set up a couple of environment secrets. These are the Discord server ID and the bot token, which are essential for the API to fetch the member count. Here's how to set them:

  • Go to the Environment Secrets tab within the Lazy Builder interface.
  • Create a new secret named `YOUR_DISCORD_SERVER_ID` and set its value to your Discord server's ID.
  • Create another secret named `YOUR_DISCORD_BOT_TOKEN` and set its value to your Discord bot's token.

Make sure you have the correct permissions and have enabled the necessary intents for your bot in the Discord developer portal to access the member count.

External Integrations

To use this template, you must have a Discord bot with the necessary permissions to access your server's member count. If you haven't already set up a bot, please follow the steps on the official Discord developer documentation to create one and invite it to your server.

Using the Test Button

Once you have set your environment secrets, you can use the Test button to deploy the app. The Lazy CLI will prompt you for any required user input. After deployment, Lazy will provide you with a dedicated server link to access the API and a docs link if you want to explore the FastAPI documentation.

How to Use the Interface

After deploying the app, you can embed the web component into your website. To do this, add the following HTML code to your site where you want the member count to appear:

<iframe src="http://your_server_address:8080/web_component" width="100%" height="100%" frameborder="0"></iframe>

Replace `http://your_server_address:8080` with the dedicated server link provided by Lazy. This iframe will display the member count on your website, and it will automatically update as the member count changes.

In summary, by following these steps, you can easily integrate the Discord Server Member Count Web Component into your website using the Lazy platform. Remember to replace the placeholders with your actual Discord server ID and bot token, and ensure your bot has the necessary permissions to access the member count data.

Technologies

Webflow Webflow
Fast API Fast API
Python Python
Discord Discord