Discord Player
Plugins

Media sources

Pass URLs, files, encoded streams, or remote operations to Remedia.

You are reading the v8 docsDev

track.stream returns the audio for a track. The Player passes it to Remedia as a media source.

Return shapes

// A URL
ctx.on('track.stream', ({ track }) => ({ url: track.url }));

// A file on the machine that runs the audio engine
ctx.on('track.stream', ({ track }) => ({ file: track.url }));

// An encoded Node.js Readable (embedded nodes only)
ctx.on('track.stream', async ({ track }) => ({ stream: createEncodedReadable(track) }));

createEncodedReadable is your own function. These are alternatives, so a handler returns one of them. A plain HTTP(S) string, a file path string, a Uint8Array, or a Readable is also accepted.

What each node can open

SourceEmbedded nodeRemote node
HTTP(S) URLYesYes, if the server can reach it and its media policy allows it
File pathYes, on the bot machineA server-local path under the server's allowed media roots
Readable or bufferYesNo
Plugin operationNoPlayback and staging through a configured source host

A remote node runs on another machine and cannot read your bot's memory, files, or streams. For remote nodes, return a URL the server can open, or use a remote source host.

Operation sources identify a host deployment, plugin, operation, and serializable input. Remedia resolves them when playback or staging starts. They cannot be probed or moved to another node, and they do not contain a temporary media grant.

Do not assume a private local file is available on another server.

Encoded audio only

A Readable carries encoded audio such as MP3, Ogg, or M4A. Remedia selects decoding or compatible Opus passthrough. A Readable is not a place to push raw PCM or unframed Opus packets.

To modify the encoded bytes before decoding, add a stream.transform handler. It runs only for local streams, must stop when the signal aborts, and should not keep unbounded chunks in memory.

HTTP request headers

A URL source can include request headers for embedded and remote playback:

ctx.on('track.stream', ({ track }) => ({
  url: track.url,
  headers: { Referer: 'https://media.example.com/' },
}));

Treat authorization and cookies as credentials. Keep them out of Track metadata and logs. Direct URL redirects are handled by FFmpeg and may forward headers to another origin; use trusted destinations when supplying sensitive headers.

Remote-safe URLs

ctx.on('track.stream', async ({ track }, { signal }) => {
  signal.throwIfAborted();

  return { url: await createAccessibleUrl(track, { signal }) };
});

createAccessibleUrl is your function. It should check access rights and return a URL that expires.

Continue reading

Plugin lifetime

On this page