Skip to content

Module augmentation

Four interfaces can be augmented. Declare them once in a .d.ts file and the types appear everywhere — no casting, zero runtime cost.

InterfaceWhat it typesWhere it appears
QueueContextData you attach to a queuequeue.context, CreateQueueOptions, PlayOptions
CommonUserDataData you attach to a tracktrack.userData, PlayOptions, queue.add()
CommonPluginInfoPlugin-provided track/playlist metadatatrack.pluginInfo, playlist.pluginInfo
CommonPluginFiltersPlugin-provided audio filtersqueue.filters, all FilterManager methods

All augmented interfaces extend JsonObject — values must be JSON-serializable. Augmentations are compile-time only with no runtime cost.

// augment.d.ts — include this file in your tsconfig
declare module "discolink" {
interface QueueContext {
textChannelId: string;
requestedBy: string;
}
interface CommonUserData {
userId: string;
username: string;
}
interface CommonPluginFilters {
customEcho: { delay: number; decay: number };
}
}

The types flow through without any extra work:

const queue = await player.queues.create({
guildId,
voiceId,
context: { textChannelId: "123", requestedBy: "user1" }, // ✓ typed
});
queue.context.textChannelId; // ✓ string
queue.add(track, { userId: "abc", username: "Alice" }); // ✓ typed
await queue.filters.set("customEcho", { delay: 200, decay: 0.5 }); // ✓ typed
player.on("trackStart", (queue, track) => {
console.log(track.userData.username); // ✓ string
console.log(queue.context.textChannelId); // ✓ string
});

If you’re publishing a plugin package, distribute a .d.ts file alongside it that augments whichever interfaces your plugin touches.

// shared.d.ts — shipped with your package
declare module "discolink" {
interface CommonPluginFilters {
myFilter: { intensity: number };
}
interface CommonPluginInfo {
myField: string;
}
}