Operations
How handlers are chosen, ordered, cancelled, and when a handler declines.
A plugin registers handlers for named operations. Each operation has a dispatch policy that decides how results are combined.
Built-in operations
| Operation | Policy | Result |
|---|---|---|
search.query.match | collect | Score from each plugin |
search.query.resolve | first | Tracks and an optional playlist |
track.stream | first | A media source |
track.related | first | Related tracks for autoplay |
track.bridge | first | A fallback source when the track's own provider cannot stream |
stream.transform | pipe | A replacement encoded stream |
lyrics.search | collect | Lyrics results |
track.stream.resolved | broadcast | Notification only |
Dispatch policies
| Policy | Behavior |
|---|---|
first | Use the first result that is not undefined |
collect | Return all results as a list |
pipe | Pass each result to the next handler |
broadcast | Call every handler. No result |
Priority and scores
ctx.on('search.query.match', ({ query }) => (query.startsWith('https://') ? { score: 90 } : null), {
priority: 10,
});Handlers with higher priority run first. For equal priority, a higher match score wins for search matching, then registration order. Other operations use registration order to break priority ties. Legacy extractor priority changes take effect on the next dispatch. The Player resolves search candidates in order until one returns tracks.
Declining
| Return | Meaning |
|---|---|
undefined | This handler declines. The next one runs |
null | A real result of "no match" for operations that allow it |
| A throw | A failure. See the bridge exception below. |
Target or block plugins
await player.search(query, { searchEngine: 'example.direct-audio' });
await player.search(query, { searchEngine: 'ext:example.direct-audio' }); // Legacy extractor syntaxThe blockExtractors option disables plugins by ID. It applies to matching, direct execution, stream resolution, and bridging.
import { Player } from 'discord-player';
const player = new Player({ blockExtractors: ['example.direct-audio'], send });Cancellation and errors
Every handler receives { signal, guildId, queue }. signal aborts when the caller cancels or the plugin is removed. Check it during slow work:
ctx.on('track.stream', async ({ track }, { signal }) => {
signal.throwIfAborted();
return { url: track.url };
});A failing handler rejects with a PluginError that names the plugin and operation. For track.bridge, the original provider is excluded and a failing handler falls through to the next eligible provider. If none succeeds, the last bridge error is reported. Cancellation always stops dispatch. A direct track.stream failure still rejects rather than triggering bridging.
Guild context
When an operation runs for a guild, guildId and queue identify it. Searches without a guild, standalone source hosts, and
remote source hosts receive guildId: null and queue: null.
ctx.on(
'track.stream',
({ track }, { queue }) => {
console.log(`Resolving ${track.title} for ${queue?.guildId ?? 'no guild'}`);
return { url: track.url };
},
{ guildIds: ['123456789012345678'] },
);guildIds limits a handler to invocations routed for those guilds. It does not inspect the operation input, and handlers
restricted to guilds are skipped when there is no guild. See handler options.
Continue reading
Custom operations