Upgrade from version 1.x to 2.x
Version 2 of discord-player-plus
contains some breaking changes from the previous version. Not all of them might affect you but you should take a look at them after you updated to version 2.
For a full list of changes, see the changelog.
peerDependencies
The following peerDependencies have been updated in order to remove deprecated versions. If you manually installed any of them in your application, make sure the versions are compatible.
peerDependency | previous version | new version |
---|---|---|
@discordjs/opus | >= 0.5.1 | >= 0.8.0 |
discord.js | >= 14.5.0 | >= 14.8.0 |
API changes
PlayerEngine
The search
method of type PlayerEngine
and therefore all player engines has been changed to return SearchResult | null
instead of SearchResult[]
.
Previously, the search result was an array but it always contained either exactly one element or none (if no search result was found). Thats the reason why it has been changed.
If you manually use the search
method of any pre-built player engine or you created your own engines, make sure to update it accordingly.
Player
As consequence of the above described change to the PlayerEngine
type, the search()
method of the Player has also been updated the same way.
If you use the player.search()
method, make sure to change your code to:
const searchResults = await player.search("Luis Fonsi - Despacito");
const searchResult = searchResults[0];
const searchResult = await player.search("Luis Fonsi - Despacito");
if (!searchResult?.tracks.length) {
console.log("No search results found for Despacito");
} else {
console.log(
`Found ${searchResult.tracks.length} matching tracks for Despacito`
);
}