2.4.2 • Published 2 years ago

discord-portable-player v2.4.2

Weekly downloads
-
License
MIT
Repository
github
Last release
2 years ago

Discord Portable Player

Complete framework to facilitate music commands using discord.js.

downloadsBadge versionBadge code style: prettier

Installation

Install discord-portable-player

$ npm install --save discord-portable-player

Install @discordjs/opus

$ npm install --save @discordjs/opus

Install FFmpeg or Avconv

Features

A simple & easy to use, beginner friendly package with amazing features such as Audio filters, Custom extractor support & many more!

Documentation

Getting Started

First of all, you will need to register slash commands:

const { token, clientId } = require('./config.json');
const { Routes, REST, SlashCommandBuilder } = require('discord.js');

const commands = [
    new SlashCommandBuilder().setName('play').setDescription('play a song').addStringOption(option => option.setName('query').setDescription('The query to search for').setRequired(true))
].map(command => command.toJSON());
	
    
const rest = new REST({ version: '10' }).setToken(token);
(async () => {
  try {
    console.log('Started refreshing application [/] commands.');
    await rest.put(
      Routes.applicationCommands(clientId),
      { body: commands },
    );
    console.log('Successfully reloaded application [/] commands.');
  } catch (error) {
    console.error(error);
  }
})();

Now you can implement your bot's logic:

const { Client, GatewayIntentBits } = require("discord.js");
const client = new Client({ intents: [GatewayIntentBits.Guilds, GatewayIntentBits.GuildMessages, GatewayIntentBits.GuildVoiceStates]});
const { token } = require('./config.json');
const { Player } = require("discord-portable-player");
// Create a new Player (you don't need any API Key)
const player = new Player(client);
client.once("ready", () => {
    console.log("I'm ready !");
});
client.on("interactionCreate", async (interaction) => {
    if (!interaction.isChatInputCommand()) return;
    // /play track: Marshmello - Together
    if (interaction.commandName === "play") {
        if (!interaction.member.voice.channel) return await interaction.reply({ content: "You are not in a voice channel!", ephemeral: true });
        if (interaction.guild.members.me.voice.channel && interaction.member.voice.channel !== interaction.guild.members.me.voice.channel) return await interaction.reply({ content: "You are not in my voice channel!", ephemeral: true });
        const query = interaction.options.getString("query")
        const queue = player.createGuildQueue({
            metadata: interaction.channel,
	    guild: interaction.guild
        });
        
        // Verifies the voice channel
        try {
            if (!queue.connection) await queue.connect(interaction.member.voice.channel);
        } catch {
            queue.destroy();
            return await interaction.reply({ content: "Could not join your voice channel!", ephemeral: true });
        }
        await interaction.deferReply();
        const track = await player.search(query, {
            requestedBy: interaction.user
        }).then(x => x.tracks[0]);
        if (!track) return await interaction.followUp({ content: `**${query}** not found!` });
        queue.play(track);
        return await interaction.followUp({ content: `Loading track **${track.title}**!` });
    }
});
// add the trackStart event so when a song will be played this message will be sent
player.on("trackStart", (queue, track) => queue.metadata.send(`🎶 | Now playing **${track.title}**!`))
client.login(token);

Supported Sources

By default, discord-portable-player supports:

2.4.2

2 years ago

2.4.1

3 years ago

2.4.0

3 years ago

2.3.0

3 years ago

2.2.0

3 years ago

1.6.4

3 years ago

1.6.3

3 years ago

1.6.2

3 years ago

1.6.1

3 years ago

1.6.0

3 years ago

2.0.3

3 years ago

2.0.2

3 years ago

2.0.5

3 years ago

2.0.4

3 years ago

2.0.7

3 years ago

2.0.6

3 years ago

2.0.9

3 years ago

2.0.8

3 years ago

2.0.1

3 years ago

2.0.0

3 years ago

1.5.1

3 years ago

1.5.0

3 years ago

2.1.2

3 years ago

2.1.1

3 years ago

2.1.4

3 years ago

2.0.13

3 years ago

2.1.3

3 years ago

2.1.6

3 years ago

2.0.11

3 years ago

2.1.5

3 years ago

2.0.12

3 years ago

2.1.7

3 years ago

2.0.10

3 years ago

2.1.0

3 years ago

1.2.0

3 years ago

1.1.1

3 years ago

1.3.4

3 years ago

1.3.3

3 years ago

1.4.1

3 years ago

1.3.2

3 years ago

1.4.0

3 years ago

1.3.1

3 years ago

1.3.0

3 years ago

1.1.0

3 years ago

1.0.0

3 years ago

0.2.0

3 years ago

0.1.1-dev

3 years ago

0.1.0-dev

3 years ago

0.0.1-dev

3 years ago