Build bots for Mercys.

Create a bot, add it to your server and let it respond to messages and events. The REST API and real-time events are ready to use.

Your first bot in three steps.

  1. Create the bot

    Open Settings › My Bots and create a new bot.

  2. Keep the token safe

    It’s shown only once. Keep it in an environment variable, not in your code.

  3. Add it to your server

    You need permission to manage bots on that server.

mercys.js isn’t on npm yet. Packages published under that name aren’t ours. Don’t install them.

Works today. Requires Node 18 and socket.io-client.

hello-bot.mjs
import { io } from 'socket.io-client';

const API = 'https://api.mercys.gg';
const auth = 'Bot ' + process.env.MERCYS_TOKEN;

const socket = io(API, { path: '/gateway', auth: { token: auth } });

socket.on('ready', () => console.log('Bot is ready.'));

socket.on('message:create', async (msg) => {
  if (msg.author.isBot || msg.content !== '!hello') return;

  const res = await fetch(API + '/api/channels/' + msg.channelId + '/messages', {
    method: 'POST',
    headers: { Authorization: auth, 'Content-Type': 'application/json' },
    body: JSON.stringify({ content: 'Hello!', replyToId: msg.id }),
  });
  if (!res.ok) console.error('Could not send the reply:', res.status);
});

Keeping your bot safe.

  • Never share the token

    If you think it leaked, regenerate it in My Bots. The old one stops working right away.

  • Which bots you can add

    You can add your own bots to a server, or bots verified by Mercys.

  • Check who sent the command

    Your bot having permission doesn’t mean the person sending the command has it too.

API reference.

The most commonly used endpoints and events.

REST endpoints

The host is api.mercys.gg. Bot management uses a user session (Bearer), while messages use a bot token (Bot).

GET /api/bots
Lists your bots
POST /api/bots
Creates a bot, up to 5 per person
POST /api/bots/:id/token
Regenerates the token and revokes the old one
DELETE /api/bots/:id
Deletes the bot, its messages and the servers it owns
POST /api/servers/:id/bots
Adds a bot to a server using { botId }
POST /api/channels/:id/messages
Sends a message
Real-time events

Connect to the /gateway path with Socket.IO. Set auth.token to “Bot ” followed by your token.

ready
The connection is ready
message:create
A new message
message:update
A message was edited
message:delete
A message was deleted
member:join
A new member joined
member:leave
A member left
server:create
The bot was added to a server
voice:state
A state changed in a voice room

We’re curious what you’ll build.

Manage your bots in Settings › My Bots, in the Windows app or in your browser.