const { bot } = require("../../index.js") const path = require("path") const { joinVoiceChannel, VoiceConnectionStatus, entersState, createAudioPlayer, createAudioResource, NoSubscriberBehavior } = require('@discordjs/voice'); module.exports = { name: 'say', description: 'Make me say something in your VC!', usage: ' ', cooldown: 1, execute(message, args) { const { voice } = message.member; if (!voice.channelId) return message.channel.send('You must be in a voice channel to use this command!') const connection = joinVoiceChannel({ channelId: voice.id, guildId: voice.guild.id, adapterCreator: voice.guild.voiceAdapterCreator, }); const player = createAudioPlayer({ behaviors: { noSubscriber: NoSubscriberBehavior.Pause, }, }); const resource = createAudioResource(path.join(__dirname, '1.mp3')); player.play(resource); connection.subscribe(player); // Subscribe the connection to the audio player (will play audio on the voice connection) const subscription = connection.subscribe(player); // subscription could be undefined if the connection is destroyed! if (subscription) { // Unsubscribe after 5 seconds (stop playing audio on the voice connection) setTimeout(() => subscription.unsubscribe(), 5_000); } connection.on(VoiceConnectionStatus.Ready, () => { console.log('The connection has entered the Ready state - ready to play audio!'); }); } }