commands/radio.js (view raw)
1const { SlashCommandBuilder } = require('discord.js');
2const { playStream, getChannel } = require('../functions/music');
3
4// const reg = /^((?:https?:)?\/\/)?((?:www|m)\.)?((?:youtube(-nocookie)?\.com|youtu.be))(\/(?:[\w\-]+\?v=|embed\/|v\/)?)([\w\-]+)(\S+)?$/;
5
6const radios = [
7 { name: 'EusariRadio', value: 'https://onair7.xdevel.com/proxy/xautocloud_cnou_1049?mp=/;stream/' },
8 { name: 'Radio 24', value: 'https://shoutcast3.radio24.ilsole24ore.com/stream.mp3' },
9 { name: 'Radio Delfino', value: 'https://nr8.newradio.it/proxy/emaamo00?mp=/stream?ext=.mp3' },
10 { name: 'Radio 105', value: 'https://icy.unitedradio.it/Radio105.mp3' },
11];
12
13module.exports = {
14 data: new SlashCommandBuilder()
15 .setName('radio')
16 .setDescription('Play a custom-defined webradio URL.')
17 .addStringOption(option =>
18 option.setName('which')
19 .setDescription('Select which radio to play')
20 .setRequired(false)
21 .addChoices(...radios)),
22
23 async execute(interaction) {
24 const channel = await getChannel(interaction);
25 if (typeof channel == 'string')
26 return await interaction.reply({ content: channel, ephemeral: true });
27
28 await interaction.deferReply();
29
30 // Get the YouTube URL or search query
31 const radio = interaction.options.getString('which');
32 const streamUrl = radio ? radio : radios[0].value;
33
34 playStream(streamUrl, channel);
35 return await interaction.editReply('Playing web radio.');
36 },
37};