src/commands/outro.ts (view raw)
1import { SlashCommandBuilder, ChatInputCommandInteraction } from 'discord.js';
2import { getChannel, queue } from '../functions/music';
3import path from 'node:path';
4const { outros } = require(path.join(process.cwd(), 'config.json'));
5
6function getOutroUrl(outro: string): string {
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' }, { name: 'No', value: 'false' })),
26
27 async execute(interaction: ChatInputCommandInteraction) {
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 queue.outro(outroUrl, channel);
36
37 if (kick !== 'false') {
38 const member = interaction.member;
39 if ("voice" in member)
40 setTimeout(() => 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};