Player Context Setup
Learn how to setup Discord Player context in your command handler
Discord Player context allows your bot to manage queues and other player specific features more efficiently. If you do not wish to use context, you may skip this guide.
Design Planning
Before we dive into the code, let's plan the design of our player context setup:
- Command Handler: We will modify the command handler to wrap
command.execute
in a player context provider. - Context Data: We will provide the necessary context data (e.g., guild) to the player context provider.
- Main Player Hook: We will use the
useMainPlayer
hook to get the main player instance.
Setting up Player Context
To set up the player context, you need to provide the context data to the player context provider. Here is an example of how you can set up the player context:
You will need to wrap command.execute
in a player context provider like this:
Keep in mind, the command handler above is just an example. Your command handler may look different. Make sure to adjust the code according to your needs.
useMainPlayer
is a hook that provides the main player instance. You must call this hook after initializing the
player.
In the example above, we are providing the guild data to the player context. This allows the player to manage the queue and other player specific features more efficiently.
In the next section, we will learn how to create play command.