const { createAudioPlayer, NoSubscriberBehavior, joinVoiceChannel, createAudioResource, StreamType } = require('@discordjs/voice'); const ytdl = require('ytdl-core'); client.on('messageCreate', async (message) => { if (message.content.startsWith('!')) { const args = message.content.replace('!', '').split(/ +/); if (args[0] === 'play') { // try { // const state = resource.audioPlayer.checkPlayable() // if (state == true) return message.reply('A music is already playing.') // } catch (error) { }; const connection = joinVoiceChannel({ channelId: message.channel.id, guildId: message.channel.guild.id, adapterCreator: message.channel.guild.voiceAdapterCreator, selfDeaf: false, selfMute: false, }); const stream = ytdl("https://www.youtube.com/watch?v=5qap5aO4i9A", { filter: "audioonly", }); const resource = createAudioResource(stream, { inputType: StreamType.Arbitrary, }); const player = createAudioPlayer(); player.play(resource); connection.subscribe(player) message.reply('Started playing music!') } if (args[0] === 'volume') { const volume = args[1]; resource.volume.setVolume(Number(volume) / 100); message.reply(`Set volume to \`${volume}\`!`) } if (args[0] === 'pause') { resource.audioPlayer.pause() message.reply(`Stopped the music!`) } if (args[0] === 'resume') { resource.audioPlayer.unpause() message.reply(`Resumed the music!`) } if (args[0] === 'stop') { resource.audioPlayer.stop() message.reply(`Stopped the music!`) } } })