A simple and easy-to-use discord music package that uses the @distube/ytdl-core, @distube/ytsr and @distube/ytpl
- Supports Youtube Tracks/Playlist
- Added
skip
,stop
,pause
andresume
. For the player class. Updates will be putted here since there's no documentations yet.
- Spotify Plugin - can play spotify songs, might also supports tracks/playlist
- Soundcloud Plugin - same as spotify, can play soundcloud songs
Install dscrd.js-player
npm i dscrd.js-player@latest
RECOMMENDED
Install ffmpeg-static and opusscript or @discordjs/opus
npm i ffmpeg-static @discordjs/opus opusscript
const { Client, GatewayIntentBits, EmbedBuiler } = require('discord.js'); //V14
const MusicPlayer = require('dscrd.js-player');
const client = new Client({
intents: [
GatewayIntentBits.Guilds,
GatewayIntentBits.GuildVoiceStates,
GatewayIntentBits.GuildMessages,
GatewayIntentBits.MessageContent
],
allowedMentions: {
parse: ["users"],
repliedUser: false
}
});
const musicPlayer = new MusicPlayer(client);
client.once('ready', () => {
console.log(`Logged in as ${client.user.tag}`);
});
client.on('messageCreate', async (msg) => {
if (msg.content.startsWith('!play')) {
const query = msg.content.split(' ').slice(1).join(' ');
await musicPlayer.play(msg, query);
}
});
client.on('messageCreate', async (msg) => {
if (msg.content.startsWith('!stop')) {
await musicPlayer.stop()
return msg.channel.send('Music Stopped.')
}
})
client.on('messageCreate', async (msg) => {
if (msg.content.startsWith('!skip')) {
await musicPlayer.skip()
return msg.channel.send('Music Skipped.')
}
})
musicPlayer.on('trackAdd', (msg, track) => {
msg.channel.send(`**${track.info.title}** has been added to the queue`);
});
musicPlayer.on('playlistAdd', (msg, playlist) => {
msg.channel.send(`**${playlist.title}** playlist has been added to the queue`);
});
musicPlayer.on('trackStart', (msg, track) => {
const embed = new EmbedBuilder()
.setTitle(track.info.title)
.setURL(track.info.video_url)
.setAuthor(
{ name: track.info.author }
)
.addFields(
{ name: 'Duration', value: `${Math.floor(track.info.lengthSeconds / 60)}:${track.info.lengthSeconds % 60}`, inline: true }
)
.setThumbnail(track.info.thumbnails[0].url)
.setDescription('Now playing in the voice channel!');
const textChannel = msg.channel;
if (textChannel) {
textChannel.send({ embeds: [embed] });
}
});
musicPlayer.on('queueEnd', (msg) => {
const textChannel = msg.channel;
if (textChannel) {
textChannel.send('The queue has ended.');
}
});
musicPlayer.on('error', (msg, error) => {
msg.channel.send(error);
});
client.login("BOT_TOKEN");
Coming SOON
You can also use this with dscrd.js. I will update this time to time also just like in dscrd.js. For now enjoy this update. I will post the updated version of it soon!