const { SlashCommandBuilder } = require("discord.js"); const { joinVoiceChannel, getVoiceConnection, createAudioPlayer, createAudioResource } = require("@discordjs/voice"); const path = require("path"); module.exports = { data: new SlashCommandBuilder() .setName("play-safety") .setDescription("Plays the safety demo!") .addChannelOption(option => option.setName("vc").setDescription("the vc that you want the bot to join!")), /** * @param {Object} options * @param {import("discord.js").Interaction} options.interaction */ run: async ({ interaction }) => { try { await interaction.deferReply() const channel = interaction.options.getChannel("vc") const connection = joinVoiceChannel({ channelId: channel.id, guildId: channel.guild.id, adapterCreator: channel.guild.voiceAdapterCreator, }) const audioPlayer = createAudioPlayer() const resource = createAudioResource(path.join(__dirname, 'audio.mp3')); audioPlayer.play() const subscription = connection.subscribe(audioPlayer) } catch (error) { console.error("An error occurred:", error.message); interaction.followUp( "An error occurred while trying to play the audio. Please check the logs." ); } }, };