const { createReadStream } = require('node:fs'); const { join } = require('node:path'); const path = require('node:path'); //const { createAudioResource, StreamType } = require('discord.js/voice'); const { Client, SlashCommandBuilder, DMChannel, GatewayIntentBits } = require('discord.js'); const { createAudioResource, StreamType, createAudioPlayer, NoSubscriberBehavior, getVoiceConnection, joinVoiceChannel, AudioPlayerStatus } = require('@discordjs/voice'); const { debug } = require('node:console'); var looping = false; module.exports = { cooldown: 5, data: new SlashCommandBuilder() .setName('ce') .setDescription('Plays the Critical Error song') .addStringOption(option => option .setName('playeraction') .setDescription('The Action the user wants to do') .setRequired(true)), async execute(interaction) { debug("LOG 1"); const userAction = interaction.options.getString("playeraction"); var botResponse = 'You are not allowed to make this command!'; const player = createAudioPlayer({ behaviors: { noSubscriber: NoSubscriberBehavior.Pause, }, }); debug("LOG 2"); if (interaction.user.id == "669981909845147661") { debug(__dirname); let resource = createAudioResource(createReadStream(path.join(__dirname, 'Inst.ogg'), { inputType: StreamType.OggOpus, })); const connection = joinVoiceChannel({ channelId: interaction.channel.id, guildId: interaction.channel.guild.id, adapterCreator: interaction.channel.guild.voiceAdapterCreator, }); botResponse = "Invalid Command"; if (userAction == "play") { player.play(resource); connection.subscribe(player); botResponse = "Playing Sound"; debug("LOG 3"); } else if (userAction == "loop") { looping = !looping; botResponse = "Looping"; } else if (userAction == "stop") { player.stop(); botResponse = "Stopping" } else if (userAction == "pause") { player.pause(); botResponse = "Pausing" } else { connection.destroy(); } }; debug("LOG 4"); /*if (botResponse != "Invalid Command") { if (looping) { player.on(AudioPlayerStatus.Idle, () => { player.play(getNextResource()); }); } else { player.on(AudioPlayerStatus.Idle, () => { debug("Nothing"); }); } }*/ player.on('error', error => { console.error(`Error: ${error.message} with resource ${error.resource.metadata.title}`); }); debug("LOG 5"); await interaction.reply(botResponse); }, };