Docs
Files
Send files the way discord.py and discord.js do, with the size and type rules, and what happens when they are crossed.
Send files the way discord.py (discord.File) and discord.js (AttachmentBuilder) do: multipart/form-data
with the message as payload_json and the files as files[0], files[1]… on
- Create Message and Edit Message,
- Create Interaction Response (types 4 and 7),
- Create Followup Message and Edit Original Interaction Response.
attachments: [{id: 0, filename: "a.png", description: "…"}] in the JSON names the file sent as
files[0] (id is its number); a file the JSON does not mention keeps the name it was sent with.
attachment://a.png in an embed's image or thumbnail then means that file. description (alt text) is
accepted and dropped: tether has none. Parts may come in any order.
An example
discord.py
import io
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)
@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 == '!file':
file = discord.File(io.BytesIO(b'Hello from a file'), filename='hello.txt')
await message.channel.send('Here you go', file=file)
client.run('YOUR BOT TOKEN')
discord.js
import { AttachmentBuilder, 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 !== '!file') return;
const file = new AttachmentBuilder(Buffer.from('Hello from a file'), { name: 'hello.txt' });
await message.channel.send({ content: 'Here you go', files: [file] });
});
client.login(process.env.BOT_TOKEN);
Limits
- Size. One file may be
MAX_UPLOAD_BYTES(25 MiB by default; the server's operator sets it, and it is theattachment_size_limitof every interaction). At most 10 files in a message, and all the files of one request together at most 4 times the one-file limit. - Checked as the bytes arrive. A file that crosses the line is answered
413with code40005(Discord's number) at once, and nothing is kept. A refused request leaves nothing behind. The answer carriesConnection: close: libraries that reuse a connection would otherwise see a reset. Files are stored as they stream in, never held whole in memory. - Type. What is stored is checked like any upload: the type is read from the bytes, executables are
refused (
40090005), and pictures are re-encoded without their metadata. - Who. Attaching needs Attach Files (and Send Messages) in the channel, checked before the first
file is read, and so is the rate limit. The upload itself has a bucket too (
attachmentRequestPerUser, 30 a minute) that is not reported in the headers. - Time. An upload that goes quiet for 30 seconds, or lasts longer than 10 minutes, is cut.
Editing
Edit Message with attachments lists the files to keep by id
([{id: "<attachment id>"}]); the others are removed, and new files in files[n] are added. Leaving
attachments out leaves the files as they are; [] removes them all. Only the author may change files,
and a message cannot end up with nothing in it (50006).
Not yet
- A private reply (
flags: 64) with a file is400: a message only one person sees is never stored, so it has nowhere to keep one. - An
ATTACHMENToption of a slash command cannot be filled from the app yet.
Downloading
There is no public CDN: a file is only served to someone allowed to read the channel. In every message a bot
may read (the gateway and the REST routes), an attachment's url is an absolute link signed for an hour
(https://<origin>/api/v1/channels/{channel.id}/attachments/…?ex=…&is=…&hm=…, Discord's own shape;
proxy_url is the same), so discord.py's await attachment.read() / save() and a plain fetch(url) work
with no token. After the hour, ask Refresh Attachment URLs, or join the path
to the origin and send Authorization: Bot <token>. (People's clients get the path and use their own
login. A bot that may not read the message gets no files at all: see
Privacy for bots.)
A message that is deleted takes its files with it: they are not served to anyone from that moment, signed
links included (404), and are removed from storage a little later.
tether's two-step upload
The web app uploads in two steps: Request Attachment Uploads answers with
a upload_url per file, PUT the raw bytes to it, then send the message with
attachments: [{id, uploaded_filename}] (the upload_filename of the answer). It works for bots too. The
same rules apply (size limit 50045 instead of 40005 there). Uploads nobody claims are deleted after an
hour.