discordac

package module
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: Apr 27, 2022 License: BSD-3-Clause Imports: 3 Imported by: 0

README

Discord Applied Commands

Discord Applied Commands is a Go package that provides an easy way to manage Discord's commands. It provides a high level API to make and register commands for your Discord Bot.

The package is in an early state of development, any kind of contribution is welcomed!

Getting Started

Installing

go get github.com/vlaetansky/discordac

Usage

Import the package

import "github.com/vlaetansky/discordac"

Firstly you need to create a DiscordGo session, it will be referred to as discordGoSession further. Please refer to a DiscordGo documentation to learn on how to create a DiscordGo Session.

Create a new DiscordAC manager which provides a high level API for managing commands

DAC = discordac.New(discordGoSession)

Next, the manager must be initialized

DAC.Init()

In order to register application commands you must first open a websocket connection

discordGoSession.Open()

You can now create your own commands (example commands) and register them with

DAC.RegisterCommands(...SlashedCommands)

You can register a particular command separately, this can be useful to register a command in a specific guild:

DAC.RegisterCommand(...SlashedCommands)

Note: generally you should register your commands using RegisterCommands(..SlashedCommands) method to avoid sending too many command creation requests to Discord API

(Please refer to the examples folder to learn more)

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type AppliedCommand

type AppliedCommand struct {
	Specification *discordgo.ApplicationCommand
	// TODO: find a better approach with guild id?
	GuildId string
	// Command implementation
	Handler func(cc *CommandContext)
}

AppliedCommand is a command representation inside DiscordAC Wraps command specification described by discordgo.ApplicationCommand and holds a corresponding command handler

func (AppliedCommand) Global

func (sc AppliedCommand) Global() bool

Global determines either SlashCommand is defined to run globally or in AppliedCommand.GuildId

func (AppliedCommand) InternalName

func (sc AppliedCommand) InternalName() string

func (AppliedCommand) Invoke

func (sc AppliedCommand) Invoke(cc *CommandContext)

Invoke calls AppliedCommand.Handler cc : CommandContext around which the command will run

func (AppliedCommand) Name

func (sc AppliedCommand) Name() string

Name returns command name

type CommandContext

type CommandContext struct {
	// Session is a connection to Discord API
	Session *discordgo.Session
	// Interaction is what issued the command to execute
	Interaction *discordgo.Interaction
	// Options are provided command options to use during execution
	Options map[string]*discordgo.ApplicationCommandInteractionDataOption
}

CommandContext is a command execution context to execute it around It includes everything which is related and is useful to command execution

func (*CommandContext) DeleteResponse

func (cc *CommandContext) DeleteResponse() (err error)

func (*CommandContext) EditResponse

func (cc *CommandContext) EditResponse(content string) (err error)

func (*CommandContext) FollowupCreate

func (cc *CommandContext) FollowupCreate(content string) (FollowupMessage, error)

func (*CommandContext) GetOption

func (cc *CommandContext) GetOption(option string) (value *discordgo.ApplicationCommandInteractionDataOption, ok bool)

func (*CommandContext) Respond

func (cc *CommandContext) Respond(content string)

type DiscordAC

type DiscordAC struct {
	// contains filtered or unexported fields
}

DiscordAC represents a high level API to command management

func New

func New(s *discordgo.Session) (dislash *DiscordAC)

New creates a new DiscordAC manager s : bot session

func (*DiscordAC) Init

func (ds *DiscordAC) Init()

Init initializes command dispatcher by adding a new handler which dispatches and invokes commands

func (*DiscordAC) RegisterCommand

func (ds *DiscordAC) RegisterCommand(guildId string, command *AppliedCommand) error

RegisterCommand registers a single command guildId : guild to register the commands in, leave blank to register it globally command : command to register

func (*DiscordAC) RegisterCommands

func (ds *DiscordAC) RegisterCommands(guildId string, commands ...*AppliedCommand) error

RegisterCommands registers a list of commands guildId : guild to register the commands in, leave blank to register it globally commands : commands to register

func (*DiscordAC) UnregisterCommands

func (ds *DiscordAC) UnregisterCommands()

UnregisterCommands unregisters all commands both globally and per guild This should be called during bot shutdown

type DispatchRequest

type DispatchRequest struct {
	Name string
	Type discordgo.InteractionType
}

type FollowupMessage

type FollowupMessage struct {
	CommandContext *CommandContext
	Message        *discordgo.Message
}

FollowupMessage TODO: move this inside CommandContext

func (FollowupMessage) Delete

func (fm FollowupMessage) Delete() (err error)

func (FollowupMessage) Edit

func (fm FollowupMessage) Edit(content string) (err error)

Directories

Path Synopsis
examples

Jump to

Keyboard shortcuts

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