-
Notifications
You must be signed in to change notification settings - Fork 1
/
deploy-commands.ts
111 lines (104 loc) · 4.55 KB
/
deploy-commands.ts
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
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
import { REST } from '@discordjs/rest';
import { Routes } from 'discord-api-types/v9';
import { SlashCommandBuilder, SlashCommandSubcommandBuilder } from '@discordjs/builders';
import RadiYo from './RadiYo';
import { ApplicationCommandPermissionData, Client, Intents } from 'discord.js';
import genres from './util/genres';
const commands = [
new SlashCommandBuilder().setName('radio')
.setDescription('Play a radio station in voice channel')
.addSubcommand(() => {
return new SlashCommandSubcommandBuilder().setName('play')
.setDescription('Play a station from an artist or station name')
.addStringOption(option => {
return option.setName('query')
.setDescription('<artist|song|station name>')
.setAutocomplete(true)
.setRequired(true);
});
})
.addSubcommand(() => {
return new SlashCommandSubcommandBuilder().setName('browse')
.setDescription('Discover new stations and find something right for the mood');
})
.addSubcommand(() => {
return new SlashCommandSubcommandBuilder().setName('asearch')
.setDescription('Search by artist')
.addStringOption(option => {
return option.setName('query')
.setDescription('artist name')
.setAutocomplete(true)
.setRequired(true);
});
})
.addSubcommand(() => {
return new SlashCommandSubcommandBuilder().setName('stsearch')
.setDescription('Search by station title')
.addStringOption(option => {
return option.setName('query')
.setDescription('station name')
.setAutocomplete(true)
.setRequired(true);
});
})
.addSubcommand(() => {
return new SlashCommandSubcommandBuilder().setName('gsearch')
.setDescription('Search by genre')
.addStringOption(option => {
return option.setName('query')
.setDescription('station name')
.addChoices(genres.map(x => [x, x]))
.setRequired(true);
});
})
.addSubcommand(() => {
return new SlashCommandSubcommandBuilder().setName('stop')
.setDescription('Stops the music and leaves the voice channel');
})
.addSubcommand(() => {
return new SlashCommandSubcommandBuilder().setName('help')
.setDescription('Get information about RadiYo! or invite it to your server');
})
].map(command => command.toJSON());
const rest = new REST({ version: '9' }).setToken(RadiYo.DISCORD_TOKEN);
(async () => {
try {
console.log('Started deploying slash commands.');
if(process.argv[2] === '--global') {
console.log('Deploying commands globally');
await rest.put(Routes.applicationCommands(RadiYo.DISCORD_OAUTH_CLIENT_ID), {body: commands});
}
else {
console.log('Deploying commands to guild');
commands[0].default_permission = false;
await rest.put(
Routes.applicationGuildCommands(RadiYo.DISCORD_OAUTH_CLIENT_ID, RadiYo.DISCORD_GUILD_ID),
{ body: commands },
);
console.log('Successfully deployed slash commands.');
const client = new Client({intents: [Intents.FLAGS.GUILDS]});
client.login();
client.on('ready', async () => {
const guild = await client.guilds.cache.get(RadiYo.DISCORD_GUILD_ID)?.fetch();
const cmds = await guild?.commands.fetch();
const perm1: ApplicationCommandPermissionData = {
id: '179705637649776640',
type: 'USER',
permission: true
};
const perm2: ApplicationCommandPermissionData = {
id: '905569260108132393',
type: 'USER',
permission: true
};
cmds?.forEach((el) => {
console.log(`Mod perms for ${el.name}`);
el.permissions.add({permissions: [perm1,perm2]});
});
process.exit(0);
});
}
} catch (error) {
console.error(error);
}
})();