npm i @espcustomss/music
-
🎶 Music Playback for Discord - Easily integrate music playback in your Discord bot.
-
🔒 TypeScript support - Fully written in TypeScript with type definitions.
-
🚀 Simple API - Fast and intuitive music control commands, perfect for developers of all levels.
-
🔊 Queue Management - Handle play, skip, pause, stop, seek, and more music-related functions.
-
🎧 Voice Channel Integration - Automatically joins and leaves voice channels.
-
🛠️ Extensible - Easily add or modify commands with the built-in MusicCommands class.
For CommonJS:
const { Client } = require('discord.js');
const { MusicClient } = require('@espcustomss/music');
const music = new MusicClient();
const bot = new Client();
music.on('trackStart', (player, track) => {
player.textChannel?.send(`\`${track.title}\` - **${track.requestor}** has started.`);
});
bot.on('message', async (msg) => {
if (msg.author.bot) return;
if (msg.content === '.play') {
const player = getPlayer(msg);
await player.play('intro to Discord bot', { member: msg.member });
}
});
function getPlayer(msg) {
return music.get(msg.guild.id)
?? music.create({
voiceChannel: msg.member.voice.channel,
textChannel: msg.channel
});
}
bot.login('<your_bot_token>');
For EsModule And TypeScript
import { Client, GatewayIntentBits } from 'discord.js';
import { MusicClient } from '@espcustomss/music';
const music = new MusicClient();
const bot = new Client({
intents: [
GatewayIntentBits.Guilds,
GatewayIntentBits.GuildMessages,
GatewayIntentBits.MessageContent,
GatewayIntentBits.GuildVoiceStates,
GatewayIntentBits.GuildMembers
]
});
music.on('trackStart', (player, track) => player.textChannel?.send(`\`${track.title}\` - **${track.requestor}** started.`));
bot.on('messageCreate', async (msg) => {
if (msg.author.bot) return;
if (msg.content === '.play') {
const player = getPlayer(msg);
await player.play('intro to Discord bot', { member: msg.member });
}
});
function getPlayer(msg) {
return music.get(msg.guild.id)
?? music.create({
voiceChannel: msg.member.voice.channel,
textChannel: msg.channel
});
}
bot.login('<your_bot_token>');
The MusicCommands class includes a variety of useful methods to control music playback. Here are a few examples:
.play:
Play a song in the voice channel..seek:
Seek to a specific position in the current track..skip:
Skip the current track..stop:
Stop the playback and clear the queue..pause:
Pause the current track..resume:
Resume playback..volume:
Set the playback volume.
import { MusicCommands } from '@espcustomss/music';
const musicCommands = new MusicCommands(music);
bot.on('messageCreate', async (msg) => {
if (msg.content.startsWith('.play ')) {
await musicCommands.play(msg);
} else if (msg.content === '.stop') {
await musicCommands.stop(msg);
}
// Add other commands as needed
});
For a complete list of commands, events, and available methods, refer to the full documentation.
// Handling .play command to play a song
async play(msg: Message) {
const player = this.getPlayer(msg);
const query = msg.content.split('.play ')[1];
const track = await player.play(query);
const textChannel = msg.channel as TextChannel;
return textChannel.send(`**${track.title}** added to the queue.`);
}
If you need help or want to contribute to the project, feel free to join our Discord server.
This project is licensed under the MIT License - see the LICENSE file for details.