Skip to content

Commit

Permalink
Merge pull request #1945 from Androz2091/rewrite-hooks
Browse files Browse the repository at this point in the history
refactor: rewrite hooks and remove youtube
  • Loading branch information
twlite authored Nov 1, 2024
2 parents ab657cf + c389c85 commit 6160518
Show file tree
Hide file tree
Showing 114 changed files with 355 additions and 5,887 deletions.
42 changes: 19 additions & 23 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -86,28 +86,6 @@ $ npm install --save ffmpeg-binaries

> Use `FFMPEG_PATH` environment variable to load ffmpeg from custom path.
#### Streaming Library

**The following method is deprecated and will be removed in the future. Please switch to [discord-player-youtubei](https://npmjs.com/discord-player-youtubei).**

**Not recommended**:

YouTube streaming is not supported without installing one of the following package. If you want to add support for YouTube playback, you need to install a streaming library. This step is not needed if you do not plan on using youtube source.

```bash
$ npm install --save youtube-ext
# or
$ npm install --save play-dl
# or
$ npm install --save @distube/ytdl-core
# or
$ npm install --save yt-stream
# or
$ npm install --save ytdl-core
```

Once you have completed these installations, let's proceed with writing a simple music bot.

### Setup

Let's create a main player instance. This instance handles and keeps track of all the queues and its components.
Expand Down Expand Up @@ -147,13 +125,31 @@ const { Player, createErisCompat } = require('discord-player');
const player = new Player(createErisCompat(client));
```

Before you add the command, make sure to provide the context to the commands if you wish to use discord-player's hooks (like `useMainPlayer`).

### Before

```js index.js
// execute the command
await command.execute(interaction);
```

### After

```js index.js
// execute the command
await player.context.provide({ guild: interaction.guild }, () => command.execute(interaction));
```

This allows discord-player to automatically know the current guild and the queue, resulting in cleaner code and seamless integration. This eradicates the need to pass the player instance to the command or use hacks like `client.player = player`.

Let's move on to the command part. You can define the command as per your requirements. We will only focus on the command part:

```js play.js
const { useMainPlayer } = require('discord-player');

export async function execute(interaction) {
const player = useMainPlayer();
const player = useMainPlayer(); // get player instance
const channel = interaction.member.voice.channel;
if (!channel) return interaction.reply('You are not connected to a voice channel!'); // make sure we have a voice channel
const query = interaction.options.getString('query', true); // we need input/query to play
Expand Down
2 changes: 1 addition & 1 deletion apps/docs/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
"type": "git",
"url": "git+https://github.com/Androz2091/discord-player.git"
},
"author": "twlite <[email protected]>",
"author": "Twilight <[email protected]>",
"license": "MIT",
"bugs": {
"url": "https://github.com/Androz2091/discord-player/issues"
Expand Down
6 changes: 3 additions & 3 deletions apps/eris-bot/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,11 @@
"version": "1.0.0",
"main": "index.js",
"scripts": {
"start": "tsx src/index.ts"
"start": "tsx --env-file=.env src/index.ts"
},
"keywords": [],
"author": "",
"license": "ISC",
"author": "Twilight <[email protected]>",
"license": "MIT",
"description": "",
"devDependencies": {
"@types/node": "^22.2.0",
Expand Down
1 change: 0 additions & 1 deletion apps/eris-bot/src/index.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
/* eslint-disable no-console */
import 'dotenv/config';
import Eris from 'eris';
import { Player, createErisCompat } from 'discord-player';

Expand Down
7 changes: 0 additions & 7 deletions apps/music-bot/.eslintrc.json

This file was deleted.

4 changes: 0 additions & 4 deletions apps/music-bot/.gitattributes

This file was deleted.

32 changes: 0 additions & 32 deletions apps/music-bot/.gitignore

This file was deleted.

2 changes: 0 additions & 2 deletions apps/music-bot/.prettierignore

This file was deleted.

15 changes: 0 additions & 15 deletions apps/music-bot/.sapphirerc.json

This file was deleted.

7 changes: 0 additions & 7 deletions apps/music-bot/README.md

This file was deleted.

59 changes: 16 additions & 43 deletions apps/music-bot/package.json
Original file line number Diff line number Diff line change
@@ -1,50 +1,23 @@
{
"name": "music-bot",
"version": "1.0.0",
"main": "dist/index.js",
"author": "Androz2091 <[email protected]>",
"license": "MIT",
"dependencies": {
"@discord-player/equalizer": "workspace:^",
"@discord-player/extractor": "workspace:^",
"@discord-player/utils": "workspace:^",
"@discordjs/opus": "^0.9.0",
"@distube/ytdl-core": "^4.13.3",
"@sapphire/discord.js-utilities": "^6.0.3",
"@sapphire/duration": "^1.0.0",
"@sapphire/framework": "^4.2.1",
"@sapphire/plugin-api": "^5.0.1",
"@sapphire/plugin-hmr": "^2.0.0",
"@sapphire/plugin-logger": "^3.0.1",
"@skyra/env-utilities": "^1.1.0",
"colorette": "^2.0.19",
"discord-api-types": "^0.37.35",
"discord-player": "workspace:^",
"mediaplex": "^0.0.9",
"opusscript": "^0.0.8",
"play-dl": "^1.9.7",
"youtube-ext": "^1.1.23"
"description": "Test music bot",
"main": "src/index.ts",
"type": "module",
"scripts": {
"start": "tsx --env-file=.env ./src/index.ts"
},
"devDependencies": {
"@sapphire/prettier-config": "^1.4.5",
"@sapphire/ts-config": "^3.3.4",
"@swc/cli": "^0.1.62",
"@swc/core": "^1.3.37",
"@types/node": "^18.14.6",
"@types/ws": "^8.5.4",
"npm-run-all": "^4.1.5",
"prettier": "^2.8.4",
"tsc-watch": "^6.0.0",
"tsup": "^7.2.0",
"tsx": "^3.12.7",
"typescript": "^5.2.2",
"vitest": "^0.34.6"
"repository": {
"type": "git",
"url": "git+https://github.com/Androz2091/discord-player.git"
},
"scripts": {
"build": "tsup",
"start": "tsup && node dist/index.js",
"dev": "tsx ./src/index.ts",
"format": "prettier --write \"src/**/*.ts\""
"author": "twilight <[email protected]>",
"license": "MIT",
"bugs": {
"url": "https://github.com/Androz2091/discord-player/issues"
},
"prettier": "@sapphire/prettier-config"
"homepage": "https://github.com/Androz2091/discord-player#readme",
"devDependencies": {
"tsx": "^4.19.2"
}
}
3 changes: 0 additions & 3 deletions apps/music-bot/src/.env.example

This file was deleted.

70 changes: 0 additions & 70 deletions apps/music-bot/src/KarasuClient.ts

This file was deleted.

85 changes: 0 additions & 85 deletions apps/music-bot/src/commands/applemusic.ts

This file was deleted.

Loading

0 comments on commit 6160518

Please sign in to comment.