all repos — simple-discord-music-bot @ 740c3a8bc78d682b36adacd3beaa08c338ed2ccb

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

commands/outro.js (view raw)

 1const { SlashCommandBuilder } = require('discord.js');
 2const { playOutro, getChannel } = require('../functions/music');
 3const path = require('node:path');
 4const { outros } = require(path.join(process.cwd(), 'config.json'));
 5
 6function getOutroUrl(outro) {
 7    if (outro) return outro;
 8    const randomIndex = Math.floor(Math.random() * (outros.length));
 9    return outros[randomIndex].value;
10}
11
12module.exports = {
13    data: new SlashCommandBuilder()
14        .setName('outro')
15        .setDescription('Leave with an outro.')
16        .addStringOption(option =>
17            option.setName('which')
18                .setDescription('Select which outro to play')
19                .setRequired(false)
20                .addChoices(...outros))
21        .addStringOption(option =>
22            option.setName('kick')
23                .setDescription('Do you actually want to log off?')
24                .setRequired(false)
25                .addChoices({ name: 'Yes', value: 'true', default: 'true' }, { name: 'No', value: 'false' })),
26
27    async execute(interaction) {
28        const channel = await getChannel(interaction);
29        if (typeof channel == 'string')
30            return await interaction.reply({ content: channel, ephemeral: true });
31
32        const outro = interaction.options.getString('which');
33        const kick = interaction.options.getString('kick');
34        const outroUrl = getOutroUrl(outro);
35        await playOutro(outroUrl, channel);
36
37        if (kick !== 'false') {
38            setTimeout(() => interaction.member.voice.disconnect(), 20_000);
39            return await interaction.reply({ content: 'Prepare for takeoff!', ephemeral: true });
40        }
41        return await interaction.reply({ content: 'Playing outro.', ephemeral: true });
42    },
43};