commands/outro.js (view raw)
1const { SlashCommandBuilder } = require('discord.js');
2const { playUrl, 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 playUrl(outroUrl, channel);
36
37 const kick_switch = kick ? kick : 'true';
38 if (kick_switch == 'true') {
39 setTimeout(() => interaction.member.voice.disconnect(), 20_000);
40 return await interaction.reply({ content: 'Prepare for takeoff!', ephemeral: true });
41 }
42 return await interaction.reply({ content: 'Playing outro.', ephemeral: true });
43 },
44};