Statsbot - Discord

An open source Rest API bot that retrieves data from your Discord server. Features SVG Badges!

dependenciesversion commit license

Intro

Statsbot was created with express.js and acts as a RESTful API. Each function of the bot has an endpoint.

get
Server Stats

https://example.com/servers/:id.json
This returns info about the server that is specified in the "id" parameter
Request
Response
Path Parameters
id
required
number
Id of the server
200: OK
{
id: "553408019120128020",
name: "Tech Central",
members: 79,
online: 34,
channels: 29,
createdAt: "2019-03-08T02:45:53.582Z",
createdTimestamp: 1552013153582,
emojis: 23,
iconURL: "https://cdn.discordapp.com/icons/553408019120128020/2bdca74734ed8aafaafb187a6ac01897.jpg",
large: false,
owner: {
displayName: "andrejarrell",
nickname: null,
presence: {
status: "online",
game: null,
},
avatarURL: "https://cdn.discordapp.com/avatars/355518701056950283/04715f1dbc611a21689858db81bc5697.png?size=2048",
},
region: "us-east",
roles: 16,
verified: false,
}

Caching has been set to 5 minutes by default. You may change this in the code.

get
Client Stats

https://example.com/client/stats.json
This returns information about the bot
Request
Response
Path Parameters
optional
string
200: OK
{
users: 107,
servers: 1,
channels: 29,
ping: 15,
}

Ajax

With Ajax you can make request to the API within the browser

index.js
<!-- Place in your head tag -->
<script src="script.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<!-- Place in your head tag -->
<h1 class="name"></h1>
<p class="online"></p>
<img class="pic">
<p class="owner"></p>
script.js
// Using jquery to add text
$(document).ready(() => {
$.get('https://example.com/servers/553408019120128020.json', data => {
$('.name').text(data.name);
$('.online').text(`${data.members} Members`);
$('.pic').attr('src', data.iconURL);
$('.owner').text(`Owner: ${data.owner.displayName}`);
});
});

Request

Another option is to use the request module that is available in node.js. You can install it with this command: npm i request

index.js
var request = require('request');
request('https://example.com/servers/553408019120128020.json', (error, response, body) => {
console.log('error:', error);
console.log('statusCode:', response && response.statusCode);
console.log('body:', body);
});

You can run this code with: node index.js

Badges

get
Server Badge

https://example.com/badge/:type/:id.svg
Renders a svg badge for your server
Request
Response
Path Parameters
id
required
number
Id of the server
type
required
string
Choose either "members" or "owner"
Query Parameters
color
optional
string
Hexadecimal color
200: OK
<svg xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" width="149.5" height="28"><g shape-rendering="crispEdges"><path fill="#232323" d="M0 0h102.5v28H0z"/><path fill="#0080ff" d="M102.5 0h47v28H102.5z"/></g><g fill="#fff" text-anchor="middle" font-family="DejaVu Sans,Verdana,Geneva,sans-serif" font-size="100"><image x="9" y="7" width="14" height="14" xlink:href="data:image/svg+xml;base64,PHN2ZyB2aWV3Qm94PSIwIDAgMjQgMjQiIHhtbG5zPSJodHRwOi8vd3d3LnczLm9yZy8yMDAwL3N2ZyIgZmlsbD0id2hpdGUiPjxwYXRoIGQ9Ik00LjMzNCA0LjYzNmMxLjM1MS0uNzI1IDIuODUyLTEuMjIyIDQuMzkzLTEuMjY4bC4yMDUuMjVjLTEuMzYzLjM5OS0yLjY5My45MjUtMy45MiAxLjY0NS0uNTA3LjMxMi0xLjAyMy42MjQtMS40NjIgMS4wMjkgMS4xMDYtLjU1MyAyLjIzNy0xLjA3OSAzLjQzOC0xLjM5NC42NDgtLjE4MyAxLjMwMi0uMzUxIDEuOTcyLS40MjggMS42MDQtLjIyNSAzLjIzNi0uMzI1IDQuODUtLjE0NGExNy42MzcgMTcuNjM3IDAgMCAxIDMuMzk1LjczMiAxOC41OTYgMTguNTk2IDAgMCAxIDIuODA1IDEuMjAxYy0uMjQtLjI0My0uNTI0LS40MzQtLjgwNi0uNjIyLTEuMjk1LS44NjQtMi43NDEtMS40OC00LjIyNC0xLjk0LjEzMy0uMTIzLjIyLS4zNjkuNDQxLS4zMyAxLjk0Ny4xMjQgMy44MTkuODg2IDUuNCAyLjAxLjExNC4wNzQuMjQzLjE0NC4yOTEuMjhhMjguMzMzIDI4LjMzMyAwIDAgMSAyLjIwOCA2LjIwMWMuNDE0IDEuOC42NTIgMy42NDIuNjc4IDUuNDg5LjAwNS4wOTIuMDA1LjE5Mi0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E1LjQ0NS0uOTAyLjI2Ny0yLjA4My0uNDY1LTIuNzg1LS40My0uNC0xLjAzNi0uNjI2LTEuNjI0LS41NDRtNy4zNzYuMDE4Yy0xLjAxOC4xOS0xLjc0OCAxLjE5Ni0xLjczNSAyLjIxMS0uMDEzLjguMzg2IDEuNjE1IDEuMDggMi4wMzQuNDYuMjk0IDEuMDUuMzU2IDEuNTcuMi41NzktLjE2IDEuMDUtLjYxIDEuMzA0LTEuMTQ0LjQ2Mi0uOTQuMjMtMi4xODYtLjU3OS0yLjg2M2ExLjk5NCAxLjk5NCAwIDAgMC0xLjY0LS40Mzh6Ii8+PC9zdmc+"/> <text x="597.5" y="175" transform="scale(.1)" textLength="615">MEMBERS</text><text x="1260" y="175" font-weight="bold" transform="scale(.1)" textLength="230">100</text></g> </svg>