-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdeploy-commands.js
More file actions
35 lines (30 loc) · 1.16 KB
/
Copy pathdeploy-commands.js
File metadata and controls
35 lines (30 loc) · 1.16 KB
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
import { REST, Routes, ApplicationCommandType } from 'discord.js';
import { data as ziplineData } from './commands/zipline.js';
import chalk from 'chalk';
function logInfo(msg) { console.log(chalk.blue('[INFO]'), msg); }
function logSuccess(msg) { console.log(chalk.green('[SUCCESS]'), msg); }
function logError(error, ctx = '') {
console.error(chalk.red('[ERROR]'), ctx, error);
}
export async function deployCommands(token, clientId) {
const rest = new REST({ version: '10' }).setToken(token);
// Slash command
const ziplineJson = ziplineData.toJSON();
ziplineJson.contexts = [0, 1, 2]; // GUILD, BOT_DM, PRIVATE_CHANNEL
// Message context menu command
const ziplineMessageCommand = {
name: 'Upload with Zipline',
type: ApplicationCommandType.Message, // 3
contexts: [0, 1, 2], // same contexts
};
try {
logInfo('Registering global application commands...');
await rest.put(
Routes.applicationCommands(clientId),
{ body: [ziplineJson, ziplineMessageCommand] },
);
logSuccess('Application commands registered successfully.');
} catch (err) {
logError(err, 'Registering application commands');
}
}