aboutsummaryrefslogtreecommitdiff
path: root/src/commands/utilities/youtube.ts
blob: 01981735deb18c47d748b5c2eca71019d7b815f1 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
import { VoiceChannel } from 'discord.js';
import { BushCommand, BushMessage, BushSlashMessage } from '../../lib';

export default class YouTubeCommand extends BushCommand {
	constructor() {
		super('youtube', {
			aliases: ['youtube', 'yt'],
			category: 'utilities',
			description: {
				content: "Allows the user to have access to discord's in-app YouTube experiment.",
				usage: 'yt <channel>',
				examples: ['yt 785281831788216364']
			},
			args: [
				{
					id: 'channel',
					type: 'voiceChannel',
					prompt: {
						start: 'What channel would you like to use?',
						retry: '{error} Choose a valid voice channel'
					}
				}
			],
			slash: true,
			slashOptions: [
				{
					name: 'channel',
					description: 'What channel would you like to use?',
					type: 'CHANNEL',
					required: true
				}
			],
			clientPermissions: ['SEND_MESSAGES'],
			userPermissions: ['SEND_MESSAGES']
		});
	}

	public override async exec(message: BushMessage | BushSlashMessage, args: { channel: VoiceChannel }): Promise<unknown> {
		if (!args.channel?.id || args.channel?.type != 'GUILD_VOICE')
			return await message.util.reply(`${util.emojis.error} Choose a valid voice channel`);

		// @ts-ignore: jank typings
		// prettier-ignore
		const invite = await this.client.api.channels(args.channel.id).invites.post({
			data: {
				validate: null,
				max_age: 604800,
				max_uses: 0,
				target_type: 2,
				target_application_id: '755600276941176913',
				temporary: false
			}
		})
		.catch(() => {});
		if (!invite || !invite.code)
			return await message.util.reply(`${this.client.util.emojis.error} An error occurred while generating your invite.`);
		else return await message.util.send(`https://discord.gg/${invite.code}`);
	}
}