const { createAudioPlayer, createAudioResource, joinVoiceChannel, AudioPlayerStatus } = require('@discordjs/voice');
const { Client, CommandInteraction, ApplicationCommandType } = require('discord.js');
const radioStreams = [
{ name: 'TAKE ME HIGHER', url: 'https://fortnite.gg/img/items/7753/audio.mp3' },
{ name: 'CALL IT BAD LUCK', url: 'https://fortnite.gg/img/items/8385/audio.mp3' },
];
module.exports = {
name: 'radio',
description: 'plays Fortnite Radio',
type: ApplicationCommandType.ChatInput,
/**
* @param {Client} client
* @param {CommandInteraction} interaction
*/
run: async (client, interaction) => {
try {
const randomIndex = Math.floor(Math.random() * radioStreams.length);
const selectedSong = radioStreams[randomIndex];
const connection = joinVoiceChannel({
channelId: interaction.member.voice.channelId,
guildId: interaction.guild.id,
adapterCreator: interaction.guild.voiceAdapterCreator,
});
const audioPlayer = createAudioPlayer();
const resource = createAudioResource(selectedSong.url, { inlineVolume: true });
audioPlayer.play(resource);
connection.subscribe(audioPlayer);
audioPlayer.on(AudioPlayerStatus.Idle, () => {
connection.destroy();
});
await interaction.reply({ content: `Now playing: "${selectedSong.name}".` });
} catch (err) {
console.log(err);
}
},
};