Documentation
¶
Index ¶
Constants ¶
This section is empty.
Variables ¶
View Source
var Ping = SlashCommand{ Feature: dg.ApplicationCommand{ Name: "ping", Description: "Responds with 'Pong!'", }, Handler: func(s *dg.Session, i *dg.InteractionCreate) { s.InteractionRespond(i.Interaction, &dg.InteractionResponse{ Type: dg.InteractionResponseChannelMessageWithSource, Data: &dg.InteractionResponseData{ Content: "Pong!", }, }) }, }
View Source
var Rps = SlashCommand{ Feature: dg.ApplicationCommand{ Name: "rps", Description: "Play Rock Paper Scissors!", Options: []*dg.ApplicationCommandOption{ { Type: dg.ApplicationCommandOptionString, Name: "selection", Description: "Input either Rock, Paper, or Scissors", Required: true, }, }, }, Handler: func(s *dg.Session, i *dg.InteractionCreate) { playeSelected := i.ApplicationCommandData().Options[0].StringValue() rand.Seed(time.Now().UnixNano()) Options := []string{"rock", "paper", "scissors"} botSelected := Options[rand.Intn(3)] var winner string botResponse := fmt.Sprintf("You Selected *%s*, I selected *%s*\n", playeSelected, botSelected) switch isPlayerWinner(botSelected, playeSelected) { case 1: winner = "**You Win!**" case 0: winner = "**You Lose!**" case -1: winner = "**Draw!**" case -2: winner = fmt.Sprintf("**No One Wins. Invalid option '%s'.**", playeSelected) botResponse = "" } botResponse += fmt.Sprintf(winner) s.InteractionRespond(i.Interaction, &dg.InteractionResponse{ Type: dg.InteractionResponseChannelMessageWithSource, Data: &dg.InteractionResponseData{ Content: botResponse, }, }) }, }
Functions ¶
Types ¶
type SCM ¶
type SCM struct {
SlashCommands map[string]SlashCommand
}
Slash Command Manager, binds all commands to a map, the command name now is used to reference a SlashCommand
func (SCM) AddCommand ¶
func (scm SCM) AddCommand(sc SlashCommand)
type SlashCommand ¶
type SlashCommand struct {
//to avoid naming stuttering (SlashCommand.Command....) discordgo.ApplicationCommand is aliased to "Feature"
Feature dg.ApplicationCommand
//Slash Command Handler aka how the command should operate
Handler func(s *dg.Session, i *dg.InteractionCreate)
}
Wrapper Structure to couple A ApplicationCommand with a dedicated Handler
Click to show internal directories.
Click to hide internal directories.