A lightweight package designed to make it just a bit easier to play and record sound with @discordjs/voice
Discord: nab138#2035
Examples
Connect to channel and play a song, then disconnect after it's done
const{ Client, Intents }=require('discord.js');constclient=newClient({intents: [Intents.FLAGS.GUILDS,Intents.FLAGS.GUILD_MESSAGES]});constvoice=require('ezvoice')constprefix='!'client.once('ready',()=>{console.log('Ready!');});client.on('messageCreate',(message)=>{if(!message.content.startsWith(prefix))returnletcommand=message.content.slice(prefix.length)if(command=='play'){if(!message.member.voice.channel)returnmessage.reply("You're not in a voice channel!")voice.play('./song.mp3',message.member.voice.channel)}})client.login(token);
Record a user's voice to a file
const{ MessageAttachment, Client, Intents }=require('discord.js');constclient=newClient({intents: [Intents.FLAGS.GUILDS,Intents.FLAGS.GUILD_MESSAGES]});constvoice=require('ezvoice')constprefix='!'client.once('ready',()=>{console.log('Ready!');});client.on('messageCreate',(message)=>{if(!message.content.startsWith(prefix))returnletcommand=message.content.slice(prefix.length)if(command=='record'){if(!message.member.voice.channel)returnmessage.reply("You're not in a voice channel!")constconnection=voice.connectToChannel(message.member.voice.channel)voice.recordToFile(connection.receiver,message.author.id,`${message.author.id}-recording.ogg`).then(()=>{connection.destroy()constfile=newMessageAttachment('./${message.author.id}-recording.ogg');message.channel.send({content: `Here's your recording:`files:[file]})})}})client.login(token)