voice-discord
v0.0.13
Published
An NPM library which makes it easy to play audio in Discord!
Readme
🎵 This is an NPM library which makes it easy to play songs in your Discord bot. 🤖
Installation
To install this library, run the following command:
npm install voice-discord
Usage
To use this library, you need to create a new instance of the Player class. You can do this by passing your bot's client to the constructor:
Playing a song 🎶
GatewayIntentBits } = require('discord.js');
const { Player } = require('voice-discord');
const client = new Client({
intents: [
GatewayIntentBits.Guilds,
GatewayIntentBits.GuildMessages,
GatewayIntentBits.MessageContent,
GatewayIntentBits.GuildMembers,
GatewayIntentBits.GuildPresences,
GatewayIntentBits.GuildVoiceStates,
],
});
const player = new Player(client);
client.on('ready', async () => {
console.log('Ready!');
channel = client.channels.cache.get('channel id'); // or get channel some other way
await player.connect(channel); // Connect to voice channel, fires a 'connected' event
});
client.on('messageCreate', async (message) => {
if (message.content.startsWith('!play')) {
const url = message.content.split(' ')[1]; // Get URL from message
const song = await player.play(url); // Play song, fires a 'songStarted' event
message.channel.send(`Now playing: ${song.title}`); // Send a message when song starts playing
}
})
client.login('token');Pausing, Resuming, and Stopping a song ⏸️ ▶️ ⏹️
client.on('messageCreate', async (message) => {
if (message.content.startsWith('!pause')) {
player.pause(); // Pause the current song, fires a 'songPaused' event
}
if (message.content.startsWith('!resume')) {
player.resume(); // Resume the current song, fires a 'songResumed' event
}
if (message.content.startsWith('!stop')) {
player.stop(); // Stop the current song, fires a 'songStopped' event
}
})Changing the volume 🔊
client.on('messageCreate', async (message) => {
if (message.content.startsWith('!volume')) {
const volume = parseInt(message.content.split(' ')[1]); // Get volume from message
player.setVolume(volume); // Set volume, fires a 'volumeChanged' event
}
})Skipping a song ⏭️
client.on('messageCreate', async (message) => {
if (message.content.startsWith('!skip')) {
player.skip(); // Skip the current song, fires a 'songSkipped' event
}
})
Getting the current song 🎵
client.on('messageCreate', async (message) => {
if (message.content.startsWith('!current')) {
const song = player.nowPlaying // Get the current song
}
});Properties 📝
Song Properties 🎵
title- The title of the songid- The ID of the songauthor- The author of the songlength- The length of the song in secondsthumbnail- The URL of the song's thumbnaildesc- The description of the songviews- The number of views the song hasuploaded- The date the song was uploadedgenre- The genre of the songkeywords- The keywords of the songurl- The URL of the song
Playlist Properties 📜
title- The title of the playlistsongs- An array ofSongobjects
Player Properties 🤖
nowPlaying- The current songvolume- The current volumequeue- An array ofSongobjects
Options ⚙️
When creating a new instance of the Player class, you can pass an options object as the second argument. The following options are available:
leaveOnEnd- Whether or not to leave the voice channel when the queue ends. Defaults tofalse.leaveOnEmpty- Whether or not to leave the voice channel when the voice channel is empty. Defaults tofalse.
Events 🎉
The following events are available:
connected- Fired when the bot connects to a voice channel.disconnected- Fired when the bot disconnects from a voice channel.songStarted- Fired when a song starts playing.paused- Fired when a song is paused.resumed- Fired when a song is resumed.songStopped- Fired when a song is stopped.songSkipped- Fired when a song is skipped.songSkippedTo- Fired when a song is skipped to.volumeChanged- Fired when the volume is changed.queueEmpty- Fired when the queue ends.error- Fired when an error occurs.playlistStarted- Fired when a playlist starts playing.playlistAdded- Fired when a playlist is added to the queue.
Credits 📜
This library is created by LordOfCosmos or absolutegod..
Support 💬
None lmfaooooo.
