Discord Player
Plugins

Custom operations

Add your own typed operations and choose how they dispatch.

You are reading the v8 docsDev

You can add operations to the registry. This is rarely needed. Source plugins normally use the built-in operations.

Define an operation

Declare the operation's types, then register its policy on the Player:

import type { Operation } from 'discord-player';

declare module '@discord-player/plugin-host' {
  interface OperationMap {
    'track.audit': Operation<{ sourceId: string }, { accepted: boolean }, 'first'>;
  }
}

player.plugins.defineOperation('track.audit', 'first');

Plugins can then handle it, and you can run it:

ctx.on('track.audit', ({ sourceId }) => ({ accepted: sourceId.length > 0 }));

const result = await player.plugins.execute('track.audit', { sourceId: 'abc' });

Define the operation before any plugin registers a handler for it.

Choose a policy

PolicyUse when
firstOne handler should answer
collectYou want an answer from every handler
pipeHandlers transform a value in turn
broadcastHandlers only need to be notified

Keep data portable

Use JSON-compatible data for inputs and outputs if the result might be saved or sent to another process.

Limits

Custom operations run inside the bot process. They are not sent to a remote Remedia server. A source that must work with a remote audio node should return a server-accessible URL from track.stream, or run on a source host.

Continue reading

v7 extractors

On this page