Common actions
Creating Custom Hooks
Learn how to create custom discord-player hooks in your project
Hooks allow you to quickly perform actions on the queue or its components. Discord Player comes with some general purpose hooks, which can be found here.
You can also create a custom hook to fulfill your need. This guide covers how to develop a hook for discord-player.
Example
const { createHook } = require('discord-player');
const useStats = createHook((context) => {
return (node) => {
const queue = context.getQueue(node);
if (!queue) return null;
return queue.stats.generate();
};
});
module.exports = useStats;const useStats = require('./hooks/useStats.js');
async function execute(interaction) {
// use the hook you just created
const stats = useStats(interaction.guild);
if (!stats) {
console.log('no stats available');
} else {
console.log(stats); // {...}
}
}