-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdeploy-commands.js
106 lines (101 loc) · 3.44 KB
/
deploy-commands.js
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
import WEAPON1 from './weapons/splatoon1.js';
import WEAPON2 from './weapons/splatoon2.js';
import WEAPON3 from './weapons/splatoon3.js';
import getCategoryList from './converters/get-types.js';
import getSpecialList from './converters/get-specials.js';
import getSubWeaponList from './converters/get-subweapons.js';
import { CLIENT_ID, GUILD_ID, TOKEN } from './config.js';
import { REST } from '@discordjs/rest';
import { Routes } from 'discord-api-types/v9';
import { SlashCommandBuilder } from '@discordjs/builders';
function decorateStringOptionsEnum (option, idList) {
// addChoices は次のように:
// option.addChoices(
// { name: 'Funny', value: 'gif_funny' },
// { name: 'Meme', value: 'gif_meme' },
// { name: 'Movie', value: 'gif_movie' },
// ));
// 配列ではなく、引数にオブジェクトを連ねて渡す必要があるので
// function.apply を使って頑張る必要がある
option.addChoices.apply(
option,
// 特別な値 "all" を先頭に追加する
['all'].concat(idList).map(id => ({
name: id,
value: id
}))
);
return option;
}
const commands =
[
new SlashCommandBuilder()
.setName('weapon1')
.setDescription('Splatoon 1 のブキルーレット')
.addStringOption(
opt => decorateStringOptionsEnum(
opt.setName('category').setDescription('ブキ種別'),
getCategoryList(WEAPON1)
)
)
.addStringOption(
opt => decorateStringOptionsEnum(
opt.setName('subweapon').setDescription('サブウェポン'),
getSubWeaponList(WEAPON1)
)
)
.addStringOption(
opt => decorateStringOptionsEnum(
opt.setName('special').setDescription('スペシャルウェポン'),
getSpecialList(WEAPON1)
)
),
new SlashCommandBuilder()
.setName('weapon2')
.setDescription('Splatoon 2 のブキルーレット')
.addStringOption(
opt => decorateStringOptionsEnum(
opt.setName('category').setDescription('ブキ種別'),
getCategoryList(WEAPON2)
)
)
.addStringOption(
opt => decorateStringOptionsEnum(
opt.setName('subweapon').setDescription('サブウェポン'),
getSubWeaponList(WEAPON2)
)
)
.addStringOption(
opt => decorateStringOptionsEnum(
opt.setName('special').setDescription('スペシャルウェポン'),
getSpecialList(WEAPON2)
)
),
new SlashCommandBuilder()
.setName('weapon3')
.setDescription('Splatoon 3 のブキルーレット')
.addStringOption(
opt => decorateStringOptionsEnum(
opt.setName('category').setDescription('ブキ種別'),
getCategoryList(WEAPON3)
)
)
.addStringOption(
opt => decorateStringOptionsEnum(
opt.setName('subweapon').setDescription('サブウェポン'),
getSubWeaponList(WEAPON3)
)
)
.addStringOption(
opt => decorateStringOptionsEnum(
opt.setName('special').setDescription('スペシャルウェポン'),
getSpecialList(WEAPON3)
)
)
].map(command => command.toJSON());
const rest = new REST({
version: '9'
}).setToken(TOKEN);
rest.put(Routes.applicationGuildCommands(CLIENT_ID, GUILD_ID), { body: commands })
.then(() => console.log('Successfully registered application commands.'))
.catch(console.error);