commands/radio.js (view raw)
1const { SlashCommandBuilder } = require('discord.js');
2const { playStream, getChannel } = require('../functions/music');
3const path = require('node:path');
4const { radios } = require(path.join(process.cwd(), 'config.json'));
5
6module.exports = {
7 data: new SlashCommandBuilder()
8 .setName('radio')
9 .setDescription('Play a custom-defined webradio URL.')
10 .addStringOption(option =>
11 option.setName('which')
12 .setDescription('Select which radio to play')
13 .setRequired(false)
14 .addChoices(...radios)),
15
16 async execute(interaction) {
17 const channel = await getChannel(interaction);
18 if (typeof channel == 'string')
19 return await interaction.reply({ content: channel, ephemeral: true });
20
21 await interaction.deferReply();
22
23 const radio = interaction.options.getString('which');
24 const streamUrl = radio ? radio : radios[0].value;
25
26 playStream(streamUrl, channel);
27 return await interaction.editReply('Playing web radio.');
28 },
29};