slash_commands example spelling & grammar (#905)

Co-authored-by: chris <christophpryer@gmail.com>
This commit is contained in:
chris 2021-04-10 16:24:33 -04:00 committed by GitHub
parent faf06855cf
commit 590e92e1c6
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -34,7 +34,7 @@ var (
commands = []*discordgo.ApplicationCommand{ commands = []*discordgo.ApplicationCommand{
{ {
Name: "basic-command", Name: "basic-command",
// All commands and options must have an description // All commands and options must have a description
// Commands/options without description will fail the registration // Commands/options without description will fail the registration
// of the command. // of the command.
Description: "Basic command", Description: "Basic command",
@ -63,8 +63,8 @@ var (
Required: true, Required: true,
}, },
// Required options must be listed first, because // Required options must be listed first since optional parameters
// like everyone knows - optional parameters is on the back. // always come after when they're used.
// The same concept applies to Discord's Slash-commands API // The same concept applies to Discord's Slash-commands API
{ {
@ -91,19 +91,19 @@ var (
Name: "subcommands", Name: "subcommands",
Description: "Subcommands and command groups example", Description: "Subcommands and command groups example",
Options: []*discordgo.ApplicationCommandOption{ Options: []*discordgo.ApplicationCommandOption{
// When command have subcommands/subcommand groups // When a command has subcommands/subcommand groups
// It must not have top-level options, they aren't accesible in the UI // It must not have top-level options, they aren't accesible in the UI
// in this case (at least, yet), so if command is with // in this case (at least not yet), so if a command has
// subcommands/subcommand groups registering top-level options // subcommands/subcommand any groups registering top-level options
// will fail the registration of the command // will cause the registration of the command to fail
{ {
Name: "scmd-grp", Name: "scmd-grp",
Description: "Subcommands group", Description: "Subcommands group",
Options: []*discordgo.ApplicationCommandOption{ Options: []*discordgo.ApplicationCommandOption{
// Also, subcommand groups isn't capable of // Also, subcommand groups aren't capable of
// containg options, by the name of them, you can see // containg options, by the name of them, you can see
// they can contain only subcommands // they can only contain subcommands
{ {
Name: "nst-subcmd", Name: "nst-subcmd",
Description: "Nested subcommand", Description: "Nested subcommand",
@ -179,7 +179,7 @@ var (
i.Data.Options[2].BoolValue(), i.Data.Options[2].BoolValue(),
} }
msgformat := msgformat :=
` Now you just leared 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
> bool_option: %v > bool_option: %v
@ -215,7 +215,7 @@ var (
switch i.Data.Options[0].Name { switch i.Data.Options[0].Name {
case "subcmd": case "subcmd":
content = content =
"The top-level subcommand is executed. Now try to execute nested one." "The top-level subcommand is executed. Now try to execute the nested one."
default: default:
if i.Data.Options[0].Name != "scmd-grp" { if i.Data.Options[0].Name != "scmd-grp" {
return return
@ -237,16 +237,15 @@ var (
}) })
}, },
"responses": func(s *discordgo.Session, i *discordgo.InteractionCreate) { "responses": func(s *discordgo.Session, i *discordgo.InteractionCreate) {
// Responses to a command is really important thing. // Responses to a command are very important.
// First of all, because you need to react to the interaction // First of all, because you need to react to the interaction
// by sending the response in 3 seconds after receiving, otherwise // by sending the response in 3 seconds after receiving, otherwise
// interaction will be considered invalid and you can no longer // interaction will be considered invalid and you can no longer
// use interaction token and ID for responding to the user's request // use the interaction token and ID for responding to the user's request
content := "" content := ""
// As you can see, response type names saying by themselvs // As you can see, the response type names used here are pretty self-explanatory,
// how they're used, but for those who want to get // but for those who want more information see the official documentation
// more information - read the official documentation
switch i.Data.Options[0].IntValue() { switch i.Data.Options[0].IntValue() {
case int64(discordgo.InteractionResponseChannelMessage): case int64(discordgo.InteractionResponseChannelMessage):
content = content =
@ -266,7 +265,7 @@ var (
}) })
if err != nil { if err != nil {
s.FollowupMessageCreate(s.State.User.ID, i.Interaction, true, &discordgo.WebhookParams{ s.FollowupMessageCreate(s.State.User.ID, i.Interaction, true, &discordgo.WebhookParams{
Content: "Something gone wrong", Content: "Something went wrong",
}) })
} }
return return
@ -280,7 +279,7 @@ var (
}) })
if err != nil { if err != nil {
s.FollowupMessageCreate(s.State.User.ID, i.Interaction, true, &discordgo.WebhookParams{ s.FollowupMessageCreate(s.State.User.ID, i.Interaction, true, &discordgo.WebhookParams{
Content: "Something gone wrong", Content: "Something went wrong",
}) })
return return
} }
@ -292,7 +291,7 @@ var (
}) })
if err != nil { if err != nil {
s.FollowupMessageCreate(s.State.User.ID, i.Interaction, true, &discordgo.WebhookParams{ s.FollowupMessageCreate(s.State.User.ID, i.Interaction, true, &discordgo.WebhookParams{
Content: "Something gone wrong", Content: "Something went wrong",
}) })
return return
} }
@ -301,33 +300,33 @@ var (
}) })
}, },
"followups": func(s *discordgo.Session, i *discordgo.InteractionCreate) { "followups": func(s *discordgo.Session, i *discordgo.InteractionCreate) {
// Followup messages is basically regular messages (you can create as many of them as you wish), // Followup messages are basically regular messages (you can create as many of them as you wish)
// but working as they is created by webhooks and their functional // but work as they are created by webhooks and their functionality
// is for handling additional messages after sending response. // is for handling additional messages after sending a response.
s.InteractionRespond(i.Interaction, &discordgo.InteractionResponse{ s.InteractionRespond(i.Interaction, &discordgo.InteractionResponse{
Type: discordgo.InteractionResponseChannelMessageWithSource, Type: discordgo.InteractionResponseChannelMessageWithSource,
Data: &discordgo.InteractionApplicationCommandResponseData{ Data: &discordgo.InteractionApplicationCommandResponseData{
// Note: this isn't documented, but you can use that if you want to. // Note: this isn't documented, but you can use that if you want to.
// This flag just allows to create messages visible only for the caller (user who triggered the command) // This flag just allows you to create messages visible only for the caller of the command
// of the command // (user who triggered the command)
Flags: 1 << 6, Flags: 1 << 6,
Content: "Surprise!", Content: "Surprise!",
}, },
}) })
msg, err := s.FollowupMessageCreate(s.State.User.ID, i.Interaction, true, &discordgo.WebhookParams{ msg, err := s.FollowupMessageCreate(s.State.User.ID, i.Interaction, true, &discordgo.WebhookParams{
Content: "Followup message has created, after 5 seconds it will be edited", Content: "Followup message has been created, after 5 seconds it will be edited",
}) })
if err != nil { if err != nil {
s.FollowupMessageCreate(s.State.User.ID, i.Interaction, true, &discordgo.WebhookParams{ s.FollowupMessageCreate(s.State.User.ID, i.Interaction, true, &discordgo.WebhookParams{
Content: "Something gone wrong", Content: "Something went wrong",
}) })
return return
} }
time.Sleep(time.Second * 5) time.Sleep(time.Second * 5)
s.FollowupMessageEdit(s.State.User.ID, i.Interaction, msg.ID, &discordgo.WebhookEdit{ s.FollowupMessageEdit(s.State.User.ID, i.Interaction, msg.ID, &discordgo.WebhookEdit{
Content: "Now original message is gone and after 10 seconds this message will ~~self-destruct~~ be deleted.", Content: "Now the original message is gone and after 10 seconds this message will ~~self-destruct~~ be deleted.",
}) })
time.Sleep(time.Second * 10) time.Sleep(time.Second * 10)
@ -337,7 +336,7 @@ var (
s.FollowupMessageCreate(s.State.User.ID, i.Interaction, true, &discordgo.WebhookParams{ s.FollowupMessageCreate(s.State.User.ID, i.Interaction, true, &discordgo.WebhookParams{
Content: "For those, who didn't skip anything and followed tutorial along fairly, " + Content: "For those, who didn't skip anything and followed tutorial along fairly, " +
"take a unicorn :unicorn: as reward!\n" + "take a unicorn :unicorn: as reward!\n" +
"Also, as bonus..., look at the original interaction response :D", "Also, as bonus... look at the original interaction response :D",
}) })
}, },
} }