feat(interactions): number application command option
This commit is contained in:
parent
df7555c758
commit
11283ba0ab
2 changed files with 22 additions and 12 deletions
|
@ -65,6 +65,13 @@ var (
|
||||||
MaxValue: 10,
|
MaxValue: 10,
|
||||||
Required: true,
|
Required: true,
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
Type: discordgo.ApplicationCommandOptionNumber,
|
||||||
|
Name: "number-option",
|
||||||
|
Description: "Float option",
|
||||||
|
MaxValue: 10.1,
|
||||||
|
Required: true,
|
||||||
|
},
|
||||||
{
|
{
|
||||||
Type: discordgo.ApplicationCommandOptionBoolean,
|
Type: discordgo.ApplicationCommandOptionBoolean,
|
||||||
Name: "bool-option",
|
Name: "bool-option",
|
||||||
|
@ -197,24 +204,26 @@ var (
|
||||||
// but this is much simpler
|
// but this is much simpler
|
||||||
i.ApplicationCommandData().Options[0].StringValue(),
|
i.ApplicationCommandData().Options[0].StringValue(),
|
||||||
i.ApplicationCommandData().Options[1].IntValue(),
|
i.ApplicationCommandData().Options[1].IntValue(),
|
||||||
i.ApplicationCommandData().Options[2].BoolValue(),
|
i.ApplicationCommandData().Options[2].FloatValue(),
|
||||||
|
i.ApplicationCommandData().Options[3].BoolValue(),
|
||||||
}
|
}
|
||||||
msgformat :=
|
msgformat :=
|
||||||
` Now you just learned how to use command options. Take a look to the value of which you've just entered:
|
` Now you just learned how to use command options. Take a look to the value of which you've just entered:
|
||||||
> string_option: %s
|
> string_option: %s
|
||||||
> integer_option: %d
|
> integer_option: %d
|
||||||
|
> number_option: %f
|
||||||
> bool_option: %v
|
> bool_option: %v
|
||||||
`
|
`
|
||||||
if len(i.ApplicationCommandData().Options) >= 4 {
|
if len(i.ApplicationCommandData().Options) >= 5 {
|
||||||
margs = append(margs, i.ApplicationCommandData().Options[3].ChannelValue(nil).ID)
|
margs = append(margs, i.ApplicationCommandData().Options[4].ChannelValue(nil).ID)
|
||||||
msgformat += "> channel-option: <#%s>\n"
|
msgformat += "> channel-option: <#%s>\n"
|
||||||
}
|
}
|
||||||
if len(i.ApplicationCommandData().Options) >= 5 {
|
if len(i.ApplicationCommandData().Options) >= 6 {
|
||||||
margs = append(margs, i.ApplicationCommandData().Options[4].UserValue(nil).ID)
|
margs = append(margs, i.ApplicationCommandData().Options[5].UserValue(nil).ID)
|
||||||
msgformat += "> user-option: <@%s>\n"
|
msgformat += "> user-option: <@%s>\n"
|
||||||
}
|
}
|
||||||
if len(i.ApplicationCommandData().Options) >= 6 {
|
if len(i.ApplicationCommandData().Options) >= 7 {
|
||||||
margs = append(margs, i.ApplicationCommandData().Options[5].RoleValue(nil, "").ID)
|
margs = append(margs, i.ApplicationCommandData().Options[6].RoleValue(nil, "").ID)
|
||||||
msgformat += "> role-option: <@&%s>\n"
|
msgformat += "> role-option: <@&%s>\n"
|
||||||
}
|
}
|
||||||
s.InteractionRespond(i.Interaction, &discordgo.InteractionResponse{
|
s.InteractionRespond(i.Interaction, &discordgo.InteractionResponse{
|
||||||
|
|
|
@ -57,6 +57,7 @@ const (
|
||||||
ApplicationCommandOptionChannel ApplicationCommandOptionType = 7
|
ApplicationCommandOptionChannel ApplicationCommandOptionType = 7
|
||||||
ApplicationCommandOptionRole ApplicationCommandOptionType = 8
|
ApplicationCommandOptionRole ApplicationCommandOptionType = 8
|
||||||
ApplicationCommandOptionMentionable ApplicationCommandOptionType = 9
|
ApplicationCommandOptionMentionable ApplicationCommandOptionType = 9
|
||||||
|
ApplicationCommandOptionNumber ApplicationCommandOptionType = 10
|
||||||
ApplicationCommandOptionAttachment ApplicationCommandOptionType = 11
|
ApplicationCommandOptionAttachment ApplicationCommandOptionType = 11
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@ -80,6 +81,8 @@ func (t ApplicationCommandOptionType) String() string {
|
||||||
return "Role"
|
return "Role"
|
||||||
case ApplicationCommandOptionMentionable:
|
case ApplicationCommandOptionMentionable:
|
||||||
return "Mentionable"
|
return "Mentionable"
|
||||||
|
case ApplicationCommandOptionNumber:
|
||||||
|
return "Number"
|
||||||
case ApplicationCommandOptionAttachment:
|
case ApplicationCommandOptionAttachment:
|
||||||
return "Attachment"
|
return "Attachment"
|
||||||
}
|
}
|
||||||
|
@ -381,12 +384,10 @@ func (o ApplicationCommandInteractionDataOption) UintValue() uint64 {
|
||||||
|
|
||||||
// FloatValue is a utility function for casting option value to float
|
// FloatValue is a utility function for casting option value to float
|
||||||
func (o ApplicationCommandInteractionDataOption) FloatValue() float64 {
|
func (o ApplicationCommandInteractionDataOption) FloatValue() float64 {
|
||||||
// TODO: limit calls to Number type once it is released
|
if o.Type != ApplicationCommandOptionNumber {
|
||||||
if v, ok := o.Value.(float64); ok {
|
panic("FloatValue called on data option of type " + o.Type.String())
|
||||||
return v
|
|
||||||
}
|
}
|
||||||
|
return o.Value.(float64)
|
||||||
return 0.0
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// StringValue is a utility function for casting option value to string
|
// StringValue is a utility function for casting option value to string
|
||||||
|
|
Loading…
Reference in a new issue