Skip to content

Use the API from Discord ​

Many groups organize their events on Discord. This example shows how a Discord command could use the OpenMeshTak API, so that people join an event themselves instead of an organizer adding each one by hand. It is about the API calls, not about building a Discord bot; any bot framework works.

The idea ​

A participant types /join in your Discord server. Your bot then:

  1. reads the person's Discord user ID and Discord roles;
  2. picks the matching OpenMeshTak role and group;
  3. adds the person to the event with one API call; and
  4. replies with the callsign, or with what went wrong.
Participanttypes /join in Discord
Your botmaps the Discord roles to a role and group
OpenMeshTakPUT external member returns the member or a sync issue
Your botreplies “You joined Bravo”

This does not create a login. The person becomes an event member identified by their Discord ID, nothing more. It is not "Sign in with Discord".

What the bot needs ​

  • An API client limited to this one event, with the permission members.sync.
  • The event's ID, and the slugs of the roles and groups you map to.
  • A table from Discord roles to OpenMeshTak slugs, kept in the bot's own configuration:
Discord roleOpenMeshTak roleOpenMeshTak group
Team Bravoparticipantbravo
Team Bravo Leadteam-leadbravo
Medicsmedicmedic

OpenMeshTak never sees the Discord roles. The bot decides; the API only receives the result.

The call ​

The bot sends one request per /join, the external member sync:

http
PUT /api/v1/events/{eventId}/external-members/discord/{discordUserId}
Authorization: Bearer <API key>
Content-Type: application/json

{ "username": "peter", "eventRole": "participant", "group": "bravo" }
ts
const result = await client.upsertExternalMember(eventId, "discord", discordUserId, {
  username: "peter",
  eventRole: "participant",
  group: "bravo",
});

It is safe to repeat. Running /join again after a role change updates the same member instead of creating a second one.

The reply ​

The response has one of two shapes:

outcomeMeaningWhat the bot could reply
memberThe person is a member. change says created, updated or unchanged; member holds the callsign."You joined Bravo as Peter."
sync-issueSomething needs an organizer, for example a callsign conflict or an unknown group. The membership stays unchanged."An organizer needs to check your entry."

Organizers see open sync issues in the event's members view and can resolve them there.

Going further ​

  • Web access: a Discord member has no password. With the extra permission member-claims.create, the bot can create an access link and send it to the person in a direct message, never in a channel.
  • Show the setup: read the person's profile to reply with their radio name and channels.

OpenMeshTak documentation is licensed under CC BY 4.0.