📝 Update examples
This commit is contained in:
parent
3c5665878b
commit
cff8589236
2 changed files with 23 additions and 20 deletions
42
README.md
42
README.md
|
@ -47,34 +47,33 @@ First of all, you will need to register slash commands:
|
||||||
|
|
||||||
```js
|
```js
|
||||||
const { REST } = require("@discordjs/rest");
|
const { REST } = require("@discordjs/rest");
|
||||||
const { Routes } = require("discord-api-types/v9");
|
const { Routes, ApplicationCommandOptionType } = require("discord.js");
|
||||||
|
|
||||||
const commands = [{
|
const commands = [
|
||||||
|
{
|
||||||
name: "play",
|
name: "play",
|
||||||
description: "Plays a song!",
|
description: "Plays a song!",
|
||||||
options: [
|
options: [
|
||||||
{
|
{
|
||||||
name: "query",
|
name: "query",
|
||||||
type: "STRING",
|
type: ApplicationCommandOptionType.String,
|
||||||
description: "The song you want to play",
|
description: "The song you want to play",
|
||||||
required: true
|
required: true
|
||||||
}
|
}
|
||||||
]
|
]
|
||||||
}];
|
}
|
||||||
|
];
|
||||||
|
|
||||||
const rest = new REST({ version: "9" }).setToken(process.env.DISCORD_TOKEN);
|
const rest = new REST({ version: "10" }).setToken("BOT_TOKEN");
|
||||||
|
|
||||||
(async () => {
|
(async () => {
|
||||||
try {
|
try {
|
||||||
console.log("Started refreshing application [/] commands.");
|
console.log("Started refreshing application [/] commands.");
|
||||||
|
|
||||||
await rest.put(
|
await rest.put(Routes.applicationGuildCommands(CLIENT_ID, GUILD_ID), { body: commands });
|
||||||
Routes.applicationGuildCommands(CLIENT_ID, GUILD_ID),
|
|
||||||
{ body: commands },
|
|
||||||
);
|
|
||||||
|
|
||||||
console.log("Successfully reloaded application [/] commands.");
|
console.log("Successfully reloaded application [/] commands.");
|
||||||
} catch (error) {
|
} catch(error) {
|
||||||
console.error(error);
|
console.error(error);
|
||||||
}
|
}
|
||||||
})();
|
})();
|
||||||
|
@ -83,8 +82,13 @@ const rest = new REST({ version: "9" }).setToken(process.env.DISCORD_TOKEN);
|
||||||
Now you can implement your bot's logic:
|
Now you can implement your bot's logic:
|
||||||
|
|
||||||
```js
|
```js
|
||||||
const { Client, Intents } = require("discord.js");
|
const { Client } = require("discord.js");
|
||||||
const client = new Discord.Client({ intents: [Intents.FLAGS.GUILDS, Intents.FLAGS.GUILD_MESSAGES, Intents.FLAGS.GUILD_VOICE_STATES] });
|
const client = new Discord.Client({
|
||||||
|
intents: [
|
||||||
|
"Guilds",
|
||||||
|
"GuildVoiceStates"
|
||||||
|
]
|
||||||
|
});
|
||||||
const { Player } = require("discord-player");
|
const { Player } = require("discord-player");
|
||||||
|
|
||||||
// Create a new Player (you don't need any API Key)
|
// Create a new Player (you don't need any API Key)
|
||||||
|
@ -98,14 +102,14 @@ client.once("ready", () => {
|
||||||
});
|
});
|
||||||
|
|
||||||
client.on("interactionCreate", async (interaction) => {
|
client.on("interactionCreate", async (interaction) => {
|
||||||
if (!interaction.isCommand()) return;
|
if (!interaction.isChatInputCommand()) return;
|
||||||
|
|
||||||
// /play track:Despacito
|
// /play track:Despacito
|
||||||
// will play "Despacito" in the voice channel
|
// will play "Despacito" in the voice channel
|
||||||
if (interaction.commandName === "play") {
|
if (interaction.commandName === "play") {
|
||||||
if (!interaction.member.voice.channelId) return await interaction.reply({ content: "You are not in a voice channel!", ephemeral: true });
|
if (!interaction.member.voice.channelId) return await interaction.reply({ content: "You are not in a voice channel!", ephemeral: true });
|
||||||
if (interaction.guild.me.voice.channelId && interaction.member.voice.channelId !== interaction.guild.me.voice.channelId) return await interaction.reply({ content: "You are not in my voice channel!", ephemeral: true });
|
if (interaction.guild.members.me.voice.channelId && interaction.member.voice.channelId !== interaction.guild.members.me.voice.channelId) return await interaction.reply({ content: "You are not in my voice channel!", ephemeral: true });
|
||||||
const query = interaction.options.get("query").value;
|
const query = interaction.options.getString("query");
|
||||||
const queue = player.createQueue(interaction.guild, {
|
const queue = player.createQueue(interaction.guild, {
|
||||||
metadata: {
|
metadata: {
|
||||||
channel: interaction.channel
|
channel: interaction.channel
|
||||||
|
@ -132,7 +136,7 @@ client.on("interactionCreate", async (interaction) => {
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
client.login(process.env.DISCORD_TOKEN);
|
client.login("BOT_TOKEN");
|
||||||
```
|
```
|
||||||
|
|
||||||
## Supported websites
|
## Supported websites
|
||||||
|
@ -143,14 +147,14 @@ By default, discord-player supports **YouTube**, **Spotify** and **SoundCloud**
|
||||||
|
|
||||||
Discord Player provides an **Extractor API** that enables you to use your custom stream extractor with it. Some packages have been made by the community to add new features using this API.
|
Discord Player provides an **Extractor API** that enables you to use your custom stream extractor with it. Some packages have been made by the community to add new features using this API.
|
||||||
|
|
||||||
#### [@discord-player/extractor](https://github.com/Snowflake107/discord-player-extractors) (optional)
|
#### [@discord-player/extractor](https://github.com/DevAndromeda/discord-player-extractors) (optional)
|
||||||
|
|
||||||
Optional package that adds support for `vimeo`, `reverbnation`, `facebook`, `attachment links` and `lyrics`.
|
Optional package that adds support for `vimeo`, `reverbnation`, `facebook`, `attachment links` and `lyrics`.
|
||||||
You just need to install it using `npm i --save @discord-player/extractor` (discord-player will automatically detect and use it).
|
You just need to install it using `npm i --save @discord-player/extractor` (discord-player will automatically detect and use it).
|
||||||
|
|
||||||
#### [@discord-player/downloader](https://github.com/DevSnowflake/discord-player-downloader) (optional)
|
#### [@discord-player/downloader](https://github.com/DevAndromeda/discord-player-downloader) (optional)
|
||||||
|
|
||||||
`@discord-player/downloader` is an optional package that brings support for +700 websites. The documentation is available [here](https://github.com/DevSnowflake/discord-player-downloader).
|
`@discord-player/downloader` is an optional package that brings support for +700 websites. The documentation is available [here](https://github.com/DevAndromeda/discord-player-downloader).
|
||||||
|
|
||||||
## Examples of bots made with Discord Player
|
## Examples of bots made with Discord Player
|
||||||
|
|
||||||
|
|
|
@ -713,7 +713,6 @@ class Queue<T = unknown> {
|
||||||
if (typeof volumeTransformer.setSmoothness === "function") volumeTransformer.setSmoothness(this.options.volumeSmoothness || 0);
|
if (typeof volumeTransformer.setSmoothness === "function") volumeTransformer.setSmoothness(this.options.volumeSmoothness || 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
setTimeout(() => {
|
setTimeout(() => {
|
||||||
this.connection.playStream(resource);
|
this.connection.playStream(resource);
|
||||||
}, this.#getBufferingTimeout()).unref();
|
}, this.#getBufferingTimeout()).unref();
|
||||||
|
|
Loading…
Reference in a new issue