-
Notifications
You must be signed in to change notification settings - Fork 780
/
commands.go
195 lines (185 loc) · 5.61 KB
/
commands.go
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
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
package main
import "github.com/bwmarrin/discordgo"
var integerOptionMinValue = 1.0
var commands = []*discordgo.ApplicationCommand{
{
Name: "basic-command",
// All commands and options must have a description
// Commands/options without description will fail the registration
// of the command.
Description: "Basic command",
},
{
Name: "basic-command-with-files",
Description: "Basic command with files",
},
{
Name: "localized-command",
Description: "Localized command. Description and name may vary depending on the Language setting",
NameLocalizations: &map[discordgo.Locale]string{
discordgo.ChineseCN: "本地化的命令",
},
DescriptionLocalizations: &map[discordgo.Locale]string{
discordgo.ChineseCN: "这是一个本地化的命令",
},
Options: []*discordgo.ApplicationCommandOption{
{
Name: "localized-option",
Description: "Localized option. Description and name may vary depending on the Language setting",
NameLocalizations: map[discordgo.Locale]string{
discordgo.ChineseCN: "一个本地化的选项",
},
DescriptionLocalizations: map[discordgo.Locale]string{
discordgo.ChineseCN: "这是一个本地化的选项",
},
Type: discordgo.ApplicationCommandOptionInteger,
Choices: []*discordgo.ApplicationCommandOptionChoice{
{
Name: "First",
NameLocalizations: map[discordgo.Locale]string{
discordgo.ChineseCN: "一的",
},
Value: 1,
},
{
Name: "Second",
NameLocalizations: map[discordgo.Locale]string{
discordgo.ChineseCN: "二的",
},
Value: 2,
},
},
},
},
},
{
Name: "options",
Description: "Command for demonstrating options",
Options: []*discordgo.ApplicationCommandOption{
{
Type: discordgo.ApplicationCommandOptionString,
Name: "string-option",
Description: "String option",
Required: true,
},
{
Type: discordgo.ApplicationCommandOptionInteger,
Name: "integer-option",
Description: "Integer option",
MinValue: &integerOptionMinValue,
MaxValue: 10,
Required: true,
},
{
Type: discordgo.ApplicationCommandOptionNumber,
Name: "number-option",
Description: "Float option",
MaxValue: 10.1,
Required: true,
},
{
Type: discordgo.ApplicationCommandOptionBoolean,
Name: "bool-option",
Description: "Boolean option",
Required: true,
},
// Required options must be listed first since optional parameters
// always come after when they're used.
// The same concept applies to Discord's Slash-commands API
{
Type: discordgo.ApplicationCommandOptionChannel,
Name: "channel-option",
Description: "Channel option",
// Channel type mask
ChannelTypes: []discordgo.ChannelType{
discordgo.ChannelTypeGuildText,
discordgo.ChannelTypeGuildVoice,
},
Required: false,
},
{
Type: discordgo.ApplicationCommandOptionUser,
Name: "user-option",
Description: "User option",
Required: false,
},
{
Type: discordgo.ApplicationCommandOptionRole,
Name: "role-option",
Description: "Role option",
Required: false,
},
},
},
{
Name: "subcommands",
Description: "Subcommands and command groups example",
Options: []*discordgo.ApplicationCommandOption{
// When a command has subcommands/subcommand groups
// It must not have top-level options, they aren't accesible in the UI
// in this case (at least not yet), so if a command has
// subcommands/subcommand any groups registering top-level options
// will cause the registration of the command to fail
{
Name: "subcommand-group",
Description: "Subcommands group",
Options: []*discordgo.ApplicationCommandOption{
// Also, subcommand groups aren't capable of
// containing options, by the name of them, you can see
// they can only contain subcommands
{
Name: "nested-subcommand",
Description: "Nested subcommand",
Type: discordgo.ApplicationCommandOptionSubCommand,
},
},
Type: discordgo.ApplicationCommandOptionSubCommandGroup,
},
// Also, you can create both subcommand groups and subcommands
// in the command at the same time. But, there's some limits to
// nesting, count of subcommands (top level and nested) and options.
// Read the intro of slash-commands docs on Discord dev portal
// to get more information
{
Name: "subcommand",
Description: "Top-level subcommand",
Type: discordgo.ApplicationCommandOptionSubCommand,
},
},
},
{
Name: "responses",
Description: "Interaction responses testing initiative",
Options: []*discordgo.ApplicationCommandOption{
{
Name: "resp-type",
Description: "Response type",
Type: discordgo.ApplicationCommandOptionInteger,
Choices: []*discordgo.ApplicationCommandOptionChoice{
{
Name: "Channel message with source",
Value: 4,
},
{
Name: "Deferred response With Source",
Value: 5,
},
},
Required: true,
},
},
},
{
Name: "followups",
Description: "Followup messages",
},
}
var commandHandlers = map[string]func(s *discordgo.Session, i *discordgo.InteractionCreate){
"basic-command": Basic,
"basic-command-with-files": BasicWithFile,
"localized-command": Localized,
"options": Options,
"subcommands": Subcommands,
"responses": Responses,
"followups": Followups,
}