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

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		
29		channel = await getChannel(interaction);
30		if (typeof channel == "string")
31      		return await interaction.reply({ content: channel, ephemeral: true });
32
33		const outro = interaction.options.getString('which');
34		const kick = interaction.options.getString('kick');
35
36		let outro_file = outro ? outro : 'random';
37		if (outro_file == 'random')
38			outro_file = outros[Math.floor(Math.random() * (outros.length - 1)) + 1].value;
39
40		await playUrl(outro_file, channel);
41
42		const kick_switch = kick ? kick : 'true';
43		if (kick_switch == 'true') {
44			setTimeout(() => interaction.member.voice.disconnect(), 20_000);
45			return await interaction.reply({ content: `Prepare for takeoff!`, ephemeral: true });
46		}
47		return await interaction.reply({ content: `Playing outro.`, ephemeral: true });
48	},
49};