discordgo_scm

package module
v2.2.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jul 6, 2022 License: MIT Imports: 3 Imported by: 0

README

discordgo-scm

Interactions manager for discordgo, forked from ethanent/discordgo-scm.

Install

go get github.com/deathvenom54/discordgo-scm

Usage

SCM is based around the concept of a Feature. It's meant to be a somewhat future-proof way to handle all kinds of Discord interactions.

You may create Features for a number of different interaction types, including ApplicationCommand, ApplicationCommandAutocomplete, and MessageComponent.

Interaction Type Relevant Feature Properties
discordgo.InteractionApplicationCommand Type, Handler, ApplicationCommand
discordgo.InteractionApplicationCommandAutocomplete Type, Handler, ApplicationCommand
discordgo.InteractionMessageComponent Type, Handler, CustomID

Now, to actually use the library, you must create an SCM and add Features.

Create an SCM:

m := scm.NewSCM()

Add a Feature to your SCM:

m.AddFeature(myFeature)

Have your SCM handle interactions with a bot:

s.AddHandler(m.HandleInteractionCreate)

Register ApplicationCommands with your bot:

// Where s is your discordgo session

err := m.CreateCommands(s, "")
// Please handle your errors :)

Delete ApplicationCommands once bot shuts down:

m.DeleteCommands(s, "")

See the godoc for full details.

Documentation

Index

Constants

View Source
const (
	InteractionTypeApplicationCommand  = discordgo.InteractionApplicationCommand
	InteractionTypeMessageComponent    = discordgo.InteractionMessageComponent
	InteractionTypeCommandAutocomplete = discordgo.InteractionApplicationCommandAutocomplete
	InteractionTypeModalSubmit         = discordgo.InteractionModalSubmit
)

Some constants for convenience

Variables

This section is empty.

Functions

This section is empty.

Types

type Feature

type Feature struct {
	Type    discordgo.InteractionType
	Handler func(*discordgo.Session, *discordgo.InteractionCreate)

	// ApplicationCommand if Type is discordgo.InteractionApplicationCommand or discordgo.InteractionApplicationCommandAutocomplete
	// Not needed for Type discordgo.InteractionMessageComponent
	ApplicationCommand *discordgo.ApplicationCommand

	// CustomID if Type is discordgo.InteractionMessageComponent
	// can also be a regular expression
	CustomID string
}

Feature essentially represents a command or a message component that you want to receive and respond to.

type SCM

type SCM struct {
	Features []*Feature
	// contains filtered or unexported fields
}

SCM represents the interaction manager, which handles responding to interactions as well as registering slash commands with the Discord API.

func NewSCM

func NewSCM() *SCM

NewSCM creates a new SCM instance.

func (*SCM) AddFeature

func (scm *SCM) AddFeature(feature *Feature)

AddFeature adds a Feature to the SCM.

func (*SCM) AddFeatures

func (scm *SCM) AddFeatures(features []*Feature)

AddFeatures adds multiple Features to the SCM.

func (*SCM) CreateCommands

func (scm *SCM) CreateCommands(s *discordgo.Session, guildID string) error

CreateCommands registers any commands (Features with Type discordgo.InteractionApplicationCommand or discordgo.InteractionApplicationCommandAutocomplete) with the API. Leave guildID as empty string for global commands. NOTE: Bot must already be started beforehand.

func (*SCM) DeleteCommands

func (scm *SCM) DeleteCommands(s *discordgo.Session, guildID string) error

DeleteCommands deletes any commands registered using CreateCommands with the API.

func (*SCM) HandleInteractionCreate

func (scm *SCM) HandleInteractionCreate(s *discordgo.Session, i *discordgo.InteractionCreate)

HandleInteractionCreate receives incoming interactions and runs the respective Feature's Handler.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL