Skip to content

Commit

Permalink
Merge pull request #1210 from Androz2091/next
Browse files Browse the repository at this point in the history
✏️ discord.js v14 support
  • Loading branch information
twlite authored Aug 4, 2022
2 parents c7a6bf2 + 65406be commit 42ef4d1
Show file tree
Hide file tree
Showing 30 changed files with 1,048 additions and 4,143 deletions.
2 changes: 1 addition & 1 deletion .eslintignore
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
example/
examples/
node_modules/
dist/
.github/
Expand Down
3 changes: 2 additions & 1 deletion .gitattributes
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
* text=auto eol=lf
* text=auto eol=lf
*.js,*.mjs linguist-language=TypeScript
4 changes: 2 additions & 2 deletions .github/workflows/docs-deploy.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,10 @@ jobs:
- name: Checkout repository
uses: actions/checkout@master

- name: Install Node v14
- name: Install Node v18
uses: actions/setup-node@master
with:
node-version: 14
node-version: 18

- name: Install dependencies
run: npm install
Expand Down
6 changes: 1 addition & 5 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,4 @@ dist
# Yarn logs
yarn*.log

# example
example/test
example/music-bot/node_modules
example/music-bot/package-lock.json
example/music-bot/.env
dev/
3 changes: 3 additions & 0 deletions .gitmodules
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
[submodule "examples/music-bot"]
path = examples/music-bot
url = https://github.com/Androz2091/discord-music-bot
42 changes: 23 additions & 19 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -47,34 +47,33 @@ First of all, you will need to register slash commands:

```js
const { REST } = require("@discordjs/rest");
const { Routes } = require("discord-api-types/v9");
const { Routes, ApplicationCommandOptionType } = require("discord.js");

const commands = [{
const commands = [
{
name: "play",
description: "Plays a song!",
options: [
{
name: "query",
type: "STRING",
type: ApplicationCommandOptionType.String,
description: "The song you want to play",
required: true
}
]
}];
}
];

const rest = new REST({ version: "9" }).setToken(process.env.DISCORD_TOKEN);
const rest = new REST({ version: "10" }).setToken("BOT_TOKEN");

(async () => {
try {
console.log("Started refreshing application [/] commands.");

await rest.put(
Routes.applicationGuildCommands(CLIENT_ID, GUILD_ID),
{ body: commands },
);
await rest.put(Routes.applicationGuildCommands(CLIENT_ID, GUILD_ID), { body: commands });

console.log("Successfully reloaded application [/] commands.");
} catch (error) {
} catch(error) {
console.error(error);
}
})();
Expand All @@ -83,8 +82,13 @@ const rest = new REST({ version: "9" }).setToken(process.env.DISCORD_TOKEN);
Now you can implement your bot's logic:

```js
const { Client, Intents } = require("discord.js");
const client = new Discord.Client({ intents: [Intents.FLAGS.GUILDS, Intents.FLAGS.GUILD_MESSAGES, Intents.FLAGS.GUILD_VOICE_STATES] });
const { Client } = require("discord.js");
const client = new Discord.Client({
intents: [
"Guilds",
"GuildVoiceStates"
]
});
const { Player } = require("discord-player");

// Create a new Player (you don't need any API Key)
Expand All @@ -98,14 +102,14 @@ client.once("ready", () => {
});

client.on("interactionCreate", async (interaction) => {
if (!interaction.isCommand()) return;
if (!interaction.isChatInputCommand()) return;

// /play track:Despacito
// will play "Despacito" in the voice channel
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.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 });
const query = interaction.options.get("query").value;
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.getString("query");
const queue = player.createQueue(interaction.guild, {
metadata: {
channel: interaction.channel
Expand All @@ -132,7 +136,7 @@ client.on("interactionCreate", async (interaction) => {
}
});

client.login(process.env.DISCORD_TOKEN);
client.login("BOT_TOKEN");
```

## Supported websites
Expand All @@ -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/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`.
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

Expand Down
File renamed without changes.
2 changes: 0 additions & 2 deletions example/README.md

This file was deleted.

2 changes: 0 additions & 2 deletions example/music-bot/README.md

This file was deleted.

3 changes: 0 additions & 3 deletions example/music-bot/config.js

This file was deleted.

Loading

0 comments on commit 42ef4d1

Please sign in to comment.