Docs
Buttons and interactions
Embeds and buttons in messages, and how to answer a press, a menu choice or a command in time.
A bot's messages can carry embeds and components (buttons and one kind of menu). When a person presses a button, chooses in a menu or runs one of your slash commands, tether sends your bot an interaction over the gateway and holds the person's request until you answer.
Embeds and components
Create Message and Edit Message take Discord's embeds and
components from a bot. A person's request ignores both. A message needs text, an embed, a file or
a poll.
- Embeds: up to 10 per message and 6000 characters of text in all.
title,description(markdown),url,color,timestamp,footer.text,author.name,thumbnail.url,image.urlandfields. Pictures arehttp(s)addresses orattachment://<file name>of the same message. Clients never contact your address: they get a signed link on tether's picture proxy, so your server never learns who looked. (A server operator can switch the proxy off; then no embed pictures are shown.) - Components: up to 5 action rows; a row holds up to 5 buttons (styles 1 to
4, or a link button, style 5, with a
url) or one string menu or picker (people, roles, both, or channels: types 5 to 8). Everycustom_idin a message is different. A button withtether_toggleis an On/Off switch (tether-only). - Rich posts: with the flag
IS_COMPONENTS_V2a message is made of Discord's components v2 and tether's own pieces (cards, rows, setting fields): see Rich posts for bots. - Fields tether does not know are dropped, and
nullcounts as absent (Discord libraries send both). PATCHwithcomponents: []orembeds: []removes them, for example to disable a button after use. A components-only edit is not marked as edited.
An example
discord.py
import discord
import yarl
ORIGIN = 'https://app.tethr.lol' # your tether server
discord.http.Route.BASE = f'{ORIGIN}/api/v1'
discord.asset.Asset.BASE = f'{ORIGIN}/api/v1'
discord.gateway.DiscordWebSocket.DEFAULT_GATEWAY = yarl.URL(ORIGIN.replace('http', 'ws', 1) + '/gateway')
intents = discord.Intents.default()
intents.message_content = True
client = discord.Client(intents=intents)
class Press(discord.ui.View):
@discord.ui.button(label='Press me', style=discord.ButtonStyle.primary)
async def press(self, interaction: discord.Interaction, button: discord.ui.Button):
await interaction.response.send_message('Pressed!')
@client.event
async def on_ready():
print(f'Logged in as {client.user}')
@client.event
async def on_message(message):
if not message.author.bot and message.content == '!button':
await message.channel.send('Here is a button', view=Press())
client.run('YOUR BOT TOKEN')
discord.js
import {
ActionRowBuilder,
ButtonBuilder,
ButtonStyle,
Client,
Events,
GatewayIntentBits,
} from 'discord.js';
const ORIGIN = 'https://app.tethr.lol'; // your tether server
const client = new Client({
intents: [
GatewayIntentBits.Guilds,
GatewayIntentBits.GuildMessages,
GatewayIntentBits.MessageContent,
],
rest: { api: `${ORIGIN}/api`, version: '1', cdn: `${ORIGIN}/api/v1` },
});
client.once(Events.ClientReady, (c) => console.log(`Logged in as ${c.user.tag}`));
client.on(Events.MessageCreate, async (message) => {
if (message.author.bot || message.content !== '!button') return;
const row = new ActionRowBuilder().addComponents(
new ButtonBuilder().setCustomId('press').setLabel('Press me').setStyle(ButtonStyle.Primary),
);
await message.channel.send({ content: 'Here is a button', components: [row] });
});
client.on(Events.InteractionCreate, async (interaction) => {
if (interaction.isButton() && interaction.customId === 'press')
await interaction.reply('Pressed!');
});
client.login(process.env.BOT_TOKEN);
Write !button, press the button, and the bot answers Pressed!. (The bot needs its prefix ! registered,
as in Getting started.)
What you receive
A press sends INTERACTION_CREATE over the gateway, with no intent needed, in Discord's shape:
{
"id": "…",
"application_id": "<your bot's id>",
"type": 3,
"token": "…",
"guild_id": "…",
"channel_id": "…",
"member": { "user": {}, "permissions": "…" },
"user": {},
"message": {},
"data": { "custom_id": "press", "component_type": 2 }
}
type is 2 for a slash command, 3 for a button or menu (menu choices are in data.values), 4 for an
autocomplete and 5 for a form. Interactions work in servers only: a button in a direct message is
drawn but a press is refused (Unknown Channel).
Answering
The first answer is due within 3 seconds (INTERACTION_TIMEOUT_MS); otherwise the person sees "The bot
didn't respond" (504, code 90210), and a late callback is 404 10062. Answering twice is 400
40060. If the work is slow, defer first (discord.py's defer() is a callback) and finish later.
Answer with Create Interaction Response. It needs no Authorization: the
interaction's token is the credential, and it is only ever sent to your bot.
type |
Meaning |
|---|---|
4 |
A message: data: {content, embeds, components, flags}. Public, it is posted as the bot in the channel. With flags: 64 only the person who pressed sees it. |
5 |
"I'll answer later": follow-ups come after. |
6 |
Nothing to show: the press is acknowledged. |
7 |
Change the message the button is on (data: {content?, embeds?, components?}). |
8 |
The choices of an autocomplete: up to 25 for a slash command's option, 12 for the player's search. |
9 |
A form to fill in (a modal): see "Forms" below. For a slash command or a button or menu press. |
A private message (flags: 64) is sent only to the presser's sessions as a MESSAGE_CREATE with the
ephemeral flag and is never stored; its buttons come back to your bot for 15 minutes (editing it does not
start the 15 minutes again). A bot keeps at most 500 private replies alive at a time: the oldest one stops
answering presses when it makes the 501st. Reading, editing and deleting a private reply needs the bot to still
be in the server. It cannot carry files yet (400).
Whatever the callback and the webhook routes hand back to your bot (the resource.message of
?with_response=true, Get and Edit Original, a follow-up's answer) follows the same content rule as the
gateway: the text, embeds and files of a message your bot may not read are empty, also in the quoted
message of a reply, and files come with signed links.
?with_response=true (or 1, which is what discord.py sends) answers 200 with Discord's
InteractionCallbackResponse instead of 204; discord.py needs it for send_message(), defer() and
edit_message().
Forms (modals)
Answer a slash command or a button or menu press with callback type 9 and a modal, exactly as
interaction.response.send_modal(modal) (discord.py) and interaction.showModal(modal) (discord.js) do. The
app shows the person a pop-up with the title and the questions, and when they press Send the bot gets an
INTERACTION_CREATE of type 5 with the answers, to answer like any interaction (a message, defer(), or,
when the form was opened from a button, update_message()).
- Questions. Up to 5, each in the shape your library sends: a Label (type
18:label,descriptionand the input inside) or an action row (type1) holding one text input that has its ownlabel, which is whatdiscord.ui.ModalandModalBuilderstill send. A text input is one line or a paragraph, withmin_length,max_length,required(default true),placeholderand a startingvalue. A menu (type3) takes one choice (max_valuesabove 1 is400);default: trueon an option starts it chosen. Titles and labels are at most 45 characters, as on Discord. - Pickers (types 5 to 8) go in a Label like a menu and may take several (
max_valuesup to 25); the answer has the ids invaluesand what they stand for indata.resolved(Rich posts for bots). - Not offered: file uploads and text displays inside a
modal (
400, naming what is wrong). - The answers come back in the shape you asked in: each answer in the Label or the action row its question
was in, so
fields.getTextInputValue(id)and discord.py'sTextInput.valueread them. A text input nobody filled in is""; an unanswered menu isvalues: []. - The server checks the answers against what you asked (required, lengths, a menu's options) and only takes a form from the person it was shown to, in the channel it was opened in, once: it is taken the moment it is sent, so a double click or a replay reaches your bot one time. It is only given back if your bot never got the interaction; if your bot is silent for 3 seconds the person sees "The bot didn't respond" and the form is gone (your bot may have it). A form not sent within 15 minutes lapses.
- Two bots, or a bot and a post, may use the same
custom_id: the app sends back a handle the server made (tether_form.idin the answer that opened it), so a form can only reach the bot that opened it. Acustom_idthe server uses for its own forms (post:…) is refused (400). The app shows the bot's name and picture above the form's title, so a form is never taken for tether's own. - A form can only be the first answer to a command or a press (
400after a message, for a modal submit, an autocomplete or a player control).
Follow-ups
For up to 15 minutes and at most 5, after the first answer (400 90211 before it):
- Create Followup Message:
POST /webhooks/{application.id}/{interaction.token}(flags: 64for a private one); - Get (discord.js
fetchReply(), discord.pyoriginal_response()), Edit and Delete the original, at…/messages/@original: the first message your answer made, or else the one the button is on. The same routes take the id a follow-up answered with (…/messages/{message.id}), sofollowup.send()results can be edited and deleted. They work on private messages too: the person sees the change at once. A token opens only the messages of its own interaction; any other id is40410008.
No other webhook routes exist.
Limits
- Replies and follow-ups are at most 2000 characters (messages sent with Create Message take 4000).
- Interactions and their tokens are kept in memory, so they need a single tether process.
- Public replies need the bot's Send Messages in that channel and go through the same checks as any message sent by REST (auto-mod and the rest).