🎵 This is an NPM library which makes it easy to play songs in your Discord bot. 🤖
To install this library, run the following command:
npm install voice-discord
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:
const { Client, 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.name}`); // Send a message when song starts playing
}
})
client.login('token');
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
}
})
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
}
})
client.on('messageCreate', async (message) => {
if (message.content.startsWith('!skip')) {
player.skip(); // Skip the current song, fires a 'songSkipped' event
}
})
client.on('messageCreate', async (message) => {
if (message.content.startsWith('!current')) {
const song = player.nowPlaying // Get the current song
}
});
This library is created by LordOfCosmos or absolutegod..
None lmfaooooo.