all repos — simple-discord-music-bot @ f5ac8b7e1de04b34091806153194cabdf9c24c6e

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

commands/outro.js (view raw)

 1const { SlashCommandBuilder } = require('discord.js');
 2const { playUrl, getChannel } = require('../functions/music');
 3
 4const outros = [
 5    { name: 'Random!', value: 'random' },
 6    { name: 'TheFatRat - Xenogenesis', value: 'https://www.youtube.com/watch?v=6N8zvi1VNSc' },
 7    { name: 'OMFG - Hello', value: 'https://www.youtube.com/watch?v=5nYVNTX0Ib8' },
 8    { name: 'Pegboard Nerds - Disconnected', value: 'https://www.youtube.com/watch?v=YdBtx8qG68w' },
 9    { name: 'Gym Class Heroes - Stereo Hearts', value: 'https://www.youtube.com/watch?v=ThctmvQ3NGk' },
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' }, { 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 randomIndex = Math.floor(Math.random() * (outros.length - 1)) + 1;
35        const outro_file = outro ? outro : outros[randomIndex].value;
36        await playUrl(outro_file, channel);
37
38        const kick_switch = kick ? kick : 'true';
39        if (kick_switch == 'true') {
40            setTimeout(() => interaction.member.voice.disconnect(), 20_000);
41            return await interaction.reply({ content: 'Prepare for takeoff!', ephemeral: true });
42        }
43        return await interaction.reply({ content: 'Playing outro.', ephemeral: true });
44    },
45};