all repos — simple-discord-music-bot @ 9028915a52f199d9c710a9cf35f8903433faec88

A Discord bot making use of discord.js and play-yt.

src/commands/radio.ts (view raw)

 1import { SlashCommandBuilder } from 'discord.js';
 2import { playStream, getChannel } from '../functions/music';
 3import path from '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};