Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update docs for AutoComplete and minor changes #1674

Merged
merged 3 commits into from
Mar 11, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
48 changes: 47 additions & 1 deletion docs/examples/autocomplete_search.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,33 @@
# Search Autocomplete

You can return suggestions to autocomplete interaction using discord-player. Just apply something similar:
You can return song suggestions to autocomplete interaction using discord-player. Just apply something similar:

*index.js*
```js
client.on("ready", function (readyClient) {

//Discord Player Initialization
const { Player } = require("discord-player");
const player = new Player(client);

});

client.on("interactionCreate", async (interaction) => {
if (interaction.isAutocomplete()) {
//Handling autocomplete requests
...
await command.autocompleteRun(interaction);
}else if(interaction.isChatInputCommand()){
//Handling chat slashCommand requests
...
await command.execute(interaction);
}

});
```
**command** here stands for your command file. Check one of the example bot implementation to understand more.

*play.js*
```js
import { useMasterPlayer } from 'discord-player';

Expand All @@ -10,11 +36,31 @@ async function autocompleteRun(interaction) {
const query = interaction.options.getString('query', true);
const results = await player.search(query);

//Returns a list of songs with their title
return interaction.respond(
results.tracks.slice(0, 10).map((t) => ({
name: t.title,
value: t.url
}))
);
}

async function execute(interaction) {
const player = useMasterPlayer();
const query = interaction.options.getString("query");
const searchResult = await player.search(query, { requestedBy: interaction.user });

if (!searchResult.hasTracks()) { //Check if we found results for this query
await interaction.reply(`We found no tracks for ${query}!`);
return;
} else {
await player.play(interaction.member.voice.channel, searchResult, {
nodeOptions: {
metadata: interaction.channel,
//You can add more options over here
},
});
}
await interaction.reply({content: `Loading your track(s)"}`,});
}
```
14 changes: 10 additions & 4 deletions docs/faq/common_errors.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,16 @@ Make sure you have `FFmpeg` or `Avconv` available on your system.

### Install FFmpeg or Avconv

- Download from official FFmpeg website: **[https://www.ffmpeg.org/download.html](https://www.ffmpeg.org/download.html)**
- Node Module (ffmpeg-static): **[https://npmjs.com/package/ffmpeg-static](https://npmjs.com/package/ffmpeg-static)**
- Avconv: **[https://libav.org/download](https://libav.org/download)**
- Download from official FFmpeg website: **[www.ffmpeg.org/download.html](https://www.ffmpeg.org/download.html)**
- Node Module (ffmpeg-static): **[npmjs.com/package/ffmpeg-static](https://npmjs.com/package/ffmpeg-static)**
- Avconv: **[npmjs.org/package/avconv](https://npmjs.org/package/avconv)**

# "something" is not working

Try attaching `debug` listener to `player.events` to see if something strange is going on. If you are unable to solve the problem, please join our official support server 👉 [https://androz2091.fr/discord](https://androz2091.fr/discord)
- Try attaching `debug` listener to `player.events` to see if something strange is going on.

- If you are getting weird errors like something is not a constructor or version.split is not a function or something similar, please try the following:

Remove `node_modules`, `package-lock.json` or any lockfiles you have, run `npm cache clean --force` or similar command equivalent to your package manager and then run `npm install` (or the install command of your package manager)

- If you are unable to solve the problem, please join our official support server 👉 [https://androz2091.fr/discord](https://androz2091.fr/discord)
9 changes: 8 additions & 1 deletion docs/faq/how_to_access_player.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,4 +15,11 @@ This would also remove intellisense as `client` does not have a property called

The code above will not create duplicate instances of `Player`. Each time you call `Player.singleton()`, you will receive the same instance and full intellisense.

> `Player.singleton()` creates a single instance of player which is shared in the future. You can simply do `Player.singleton()` to access player instance whenever you want without polluting client.
> `Player.singleton()` creates a single instance of player which is shared in the future. You can simply do `Player.singleton()` to access player instance whenever you want without polluting client.

Once you initialize Player, you can access that instance of player from anywhere as shown below:

```js
const { useMasterPlayer } = require("discord-player");
const player = useMasterPlayer();
```
2 changes: 1 addition & 1 deletion examples/README.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
# Discord Player Examples

Examples for **[discord-player](https://github.com/Androz2091/discord-player)**.
Examples from discord-player community :[GitHub #1638](https://github.com/Androz2091/discord-player/issues/1638)