Getting Started
Follow this guide to get Disvoice running in your project. You'll have a high-quality music bot running in less than 5 minutes.
Prerequisites
Node.js 16.9.0 or higher
ffmpeg-static
@discordjs/voice
libsodium-wrappers
01
Installation
Install disvoice and the required peer dependencies.
npm install disvoice ffmpeg-static @discordjs/voice libsodium-wrappers02
Client Setup
Initialize the Disvoice player with your Discord client. Make sure to include the necessary Gateway Intents.
const { Client, GatewayIntentBits } = require('discord.js');
const { Disvoice } = require('disvoice');
const client = new Client({
intents: [
GatewayIntentBits.Guilds,
GatewayIntentBits.GuildVoiceStates, // Required for voice
GatewayIntentBits.GuildMessages,
GatewayIntentBits.MessageContent
]
});
// Create the player instance
const player = new Disvoice(client);03
Play Music
Use the play() method to join a voice channel and start streaming.
client.on('messageCreate', async message => {
if (message.content.startsWith('!play')) {
const voiceChannel = message.member.voice.channel;
const query = message.content.slice(6).trim();
if (!voiceChannel) return message.reply('Join a channel first!');
// Simple play command
await player.play(voiceChannel, query, {
textChannel: message.channel,
member: message.member
});
}
});04
Handle Events
Listen to events to keep your users updated on playback status.
player.on('playSong', (queue, song) => {
queue.textChannel.send(`🎶 Playing **${song.name}**`);
});
player.on('addSong', (queue, song) => {
queue.textChannel.send(`✅ Added **${song.name}** to queue`);
});