const { SlashCommandBuilder } = require('@discordjs/builders'); const { generateDependencyReport, AudioPlayerStatus, joinVoiceChannel, createAudioPlayer, createAudioResource } = require('@discordjs/voice'); module.exports = { data: new SlashCommandBuilder() .setName('play') .setDescription('Plays sound'), async execute(interaction) { //get the voice channel ids const voiceChannelId = '942228972626907257' const voiceChannel = interaction.client.channels.cache.get(voiceChannelId); const guildId = '933838289843142677' //create audio player const player = createAudioPlayer(); player.on(AudioPlayerStatus.Playing, () => { console.log('The audio player has started playing!'); }); player.on('error', error => { console.error(`Error: ${error.message} with resource`); }); //create and play audio const resource = createAudioResource('D:\\SL_-_Tropical_Music_Video_Mixt_(getmp3.pro).mp3'); player.play(resource); //create the connection to the voice channel const connection = joinVoiceChannel({ channelId: voiceChannelId, guildId: guildId, adapterCreator: voiceChannel.guild.voiceAdapterCreator, }) interaction.reply("created voice connection") // 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(), 30_000); } }, };