Source sessions
Some services answer a request that comes from a bot with a challenge, a rate limit, or a refusal. A plugin that talks to such a service usually takes a session: a cookie, a token, or a pair of them. The plugin documents what it expects, and the option that carries it.
What a session changes
Section titled “What a session changes”| Without a session | With one |
|---|---|
| The service asks the bot to prove it is not one | The requests look like a signed-in session |
| The rate limits are frequent | The limits are much higher |
| Some content is refused | It plays, with the rights of the account |
| Some live streams are refused | They play |
Getting a session
Section titled “Getting a session”The value is the raw header of a signed-in session, exported from a browser.
- Install a cookie exporter for your browser.
- Open the site of the service, and sign in.
- Click the extension icon, then Export.
- Copy the value.
Giving it to the plugin
Section titled “Giving it to the plugin”Every plugin names its own option. A session is a string, so it comes from the environment:
import { DisTube } from "@kattowo/distube";import { MyPlugin } from "./my-plugin.js";
const distube = new DisTube(client, { plugins: [new MyPlugin({ session: process.env.SOURCE_SESSION })],});The name of the option and the format of the value belong to the plugin. The value is the raw header, without a name:
SID=...; HSID=...; SAPISID=...; __Secure-3PAPISID=...A session can also be read from a file, which keeps it out of the environment:
import { readFileSync } from "node:fs";
const session = readFileSync("./session.txt", "utf8").trim();
const distube = new DisTube(client, { plugins: [new MyPlugin({ session })],});When it stops working
Section titled “When it stops working”A session expires, and a wrong one is refused. The symptoms are a request that fails with a challenge, with a rate limit, or with a refusal that a signed-in session does not get. When it happens, export a new one. There is no way to refresh a session by itself.
Keeping it out of the repository
Section titled “Keeping it out of the repository”A session is a credential. Keep it in the environment of the bot, and add the file that holds it to the ignore list of the repository:
session.txt