# Bots

> Klang is compatible with bots written for Discord’s API. In most cases, changing the URLs and the token is enough to run one on Klang. Bots are in a closed beta for now.

## What a bot can do today

A bot is an app with its own account. It joins the servers people add it to, gets events through
a WebSocket and acts through a REST API, with the permissions its role gives it. For what it
supports, Klang speaks the same routes, events, JSON and numbers as Discord’s API version 10, so
libraries such as discord.js, discord.py and JDA connect to it with a few lines of configuration
and no change to your bot’s logic.

Right now a bot can:

- **Read and write messages** in text channels and public threads: text up to 4,000 characters,
  replies, rich embeds, a sticker, reactions and the “is typing” indicator.
- **Have slash commands**, and commands in the menu of a person or a message, with options,
  translations and autocomplete. It answers with a message, an ephemeral message only that person
  sees, or a deferred answer, through the gateway or by HTTP. See
  [Slash commands](https://docs.klang.gg/bots/commands/).
- **Add buttons and select menus** to its messages, build messages out of layout components
  (text, images, files and boxes), and open forms with text, choices and files. See
  [Buttons, menus and layouts](https://docs.klang.gg/bots/components/) and [Modals](https://docs.klang.gg/bots/modals/).
- **Send files** with its messages, answers and webhooks. See [Sending files](https://docs.klang.gg/bots/files/).
- **Get events as they happen**: new, edited and deleted messages, reactions, people joining,
  leaving and being banned, and channels, threads, roles and the server itself changing.
- **Talk in direct messages** with people who share a server with it and allow it.
- **Read its servers**: channels, roles, members and their permissions.
- **Moderate**: kick, ban, time out, change nicknames, give roles and delete messages in bulk,
  with the same rules as a person. See [Moderation](https://docs.klang.gg/bots/reference/moderation/).
- **Post through webhooks**, with the same URLs as any other integration, and create and manage
  a server’s webhooks. See [Webhooks](https://docs.klang.gg/webhooks/) and the
  [webhook routes](https://docs.klang.gg/bots/reference/webhooks/).

A bot for moderation, logging, welcomes with roles, reaction roles, utilities, games or counters
usually runs as it is, with its slash commands, buttons, menus and forms. A bot that relies on
voice doesn’t work yet: the [compatibility table](https://docs.klang.gg/bots/compatibility/) lists every route and event,
and [Differences from Discord’s API](https://docs.klang.gg/bots/differences/) explains what behaves differently.

## The closed beta

Bots are new on Klang, so they start in a closed beta:

- **Only accounts on the beta list create apps.** They see **Settings › Developers** and the
  developer portal at [app.klang.gg/developers](https://app.klang.gg/developers).
- **Only accounts on the beta list add bots to a server.** If you want to try your bot in a
  friend’s server, they need to be on the list too.
- **Things can change.** Limits, routes and events may move while the beta lasts. We try to
  announce changes that can break a bot here and in the developer portal before they happen.

To ask for access, sign in and open
[app.klang.gg/developers](https://app.klang.gg/developers), then select **Request access**. Tell
us what you’d like to build and, if you have one, add a link to a website, a repository or a
server. You need a registered account with a confirmed email, and you have to be an adult. The
team answers in your Klang inbox: once you’re in, the same page becomes the developer portal. You
can have one request open at a time, and if it isn’t approved you can ask again 30 days later.

If something goes wrong with the request, write to [hi@klang.gg](mailto:hi@klang.gg) from the
email of your Klang account.

Within the beta, a bot can be in up to 100 servers. To go further, ask Klang’s team to
[verify it](https://docs.klang.gg/bots/getting-started/#verify-your-bot) from the developer portal.

These docs are public for everyone, beta or not, so you can see what to expect before you ask.

## Developer terms

Creating an app means accepting the
[developer terms](https://app.klang.gg/legal/developers), on top of Klang’s
[terms](https://app.klang.gg/legal/terms) and [privacy policy](https://app.klang.gg/legal/privacy).
In short:

- your bot uses the API only with its own token, and never through a person’s account;
- it always shows as a bot, and never as a person, as Klang or as another app;
- it asks only for the permissions and the data it needs, and keeps the least it can;
- you answer for what it does with the data it gets, and you delete that data when it’s no longer
  needed.

The terms themselves are what count: read them before you build.

## What people see

Klang shows bots for what they are, wherever they appear:

- **A BOT tag** next to its name, always: in messages, in the member list, on its profile and in
  mentions.
- **Server managers stay in control.** People with **Manage server** see every bot in
  **Server settings › Integrations › Bots**, who added it, when, and what its role allows, and
  they remove it with one click.
- **A bot never reads direct messages or groups between people.** It only sees the servers it’s
  in and its own direct messages, and nobody can add it to a group.
- **Bots follow the server’s rules.** Their messages go through the server’s AutoMod and slow
  mode, and moderators can delete them or time the bot out like anyone else.

## Where to go next

1. [Getting started](https://docs.klang.gg/bots/getting-started/): create an app, get its token and add its bot to a
   server.
2. [Connect your library](https://docs.klang.gg/bots/libraries/): the settings for discord.js, discord.py and JDA,
   with a small bot for each.
3. [Slash commands](https://docs.klang.gg/bots/commands/) and [Responding to interactions](https://docs.klang.gg/bots/interactions/):
   register commands and answer them.
4. [Gateway](https://docs.klang.gg/bots/gateway/) and [Limits and rate limits](https://docs.klang.gg/bots/limits/): how the connection and
   the limits work on Klang.
5. [Bot API reference](https://docs.klang.gg/bots/reference/): every route, object and event, field by field.

If you know Discord’s API well, start with
[Differences from Discord’s API](https://docs.klang.gg/bots/differences/). The [bot API reference](https://docs.klang.gg/bots/reference/)
lists every route and event Klang supports, with the fields it fills in, real examples and its
errors. [Discord’s API reference](https://docs.discord.com/developers/intro) (a third-party site)
describes the shapes Klang follows.
