gobot

package
v0.0.0-...-44b4a98 Latest Latest
Warning

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

Go to latest
Published: Apr 23, 2020 License: MIT Imports: 3 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func SinglePrefixHandler

func SinglePrefixHandler(prefix string) func(*discordgo.Message) string

SinglePrefixHandler returns a simple single-prefix handler for the bot.

Types

type Bot

type Bot struct {
	// The underlying, preconfigured discordgo session.
	Session *discordgo.Session
	// The bot's prefix handler.
	Prefix func(msg *discordgo.Message) string
	// The bot's self-description, used in help.
	Description string
	// contains filtered or unexported fields
}

Bot represents a Discord bot with commands.

func (*Bot) GetCommand

func (bot *Bot) GetCommand(commandName string) *Command

GetCommand gets a command pointer. Returns nil if command does not exist.

func (*Bot) Init

func (bot *Bot) Init()

Init initializes a new Bot instance and registers event handlers.

func (*Bot) ListCommands

func (bot *Bot) ListCommands() []string

ListCommands returns a slice of all command names.

func (*Bot) Me

func (bot *Bot) Me() *discordgo.User

Me returns the discord bot's own User instance. May return nil before the first READY.

func (*Bot) RegisterCommand

func (bot *Bot) RegisterCommand(cmd *Command)

RegisterCommand registers (and overwrites) a command in the bot.

func (*Bot) RegisterCommands

func (bot *Bot) RegisterCommands(cmds []*Command)

RegisterCommands registers multiple commands at once. This is convenient for, for instance, importing modules created by others.

func (*Bot) RemoveCommand

func (bot *Bot) RemoveCommand(commandName string)

RemoveCommand removes a command from the bot. If the command does not exist, it does nothing.

type Command

type Command struct {
	Name        string // The lowercase name of the command.
	Description string // The description to use in help.
	Category    string // A virtual group to use when sorting these commands in a helper.

	// The checks to run. If you wish to send an error message, do so in the
	// check itself before returning false.
	Checks []func(context *Context) bool
	Runner func(context *Context) // The command runner.
}

Command represents a command in a discord bot.

func DefaultHelper

func DefaultHelper() *Command

DefaultHelper returns the default help command.

type Context

type Context struct {
	Bot     *Bot     // The bot instance.
	Prefix  string   // The prefix this command was invoked with.
	Command *Command // The invoked command.
	Args    []string // The command arguments.

	Message   *discordgo.MessageCreate // The message that triggered this command.
	Author    *discordgo.Member        // Shorthand for Message.Author.
	ChannelID string                   // Shorthand for Message.ChannelID.
	GuildID   string                   // Shorthand for Message.GuildID.
}

Context provides command context.

func (*Context) Me

func (c *Context) Me() *discordgo.User

Me is a shorthand helper to Bot.Me().

func (*Context) Reply

func (c *Context) Reply(msg string) (*discordgo.Message, error)

Reply is shorthand to send a message to the channel the command was invoked from.

func (*Context) ReplyWithEmbed

func (c *Context) ReplyWithEmbed(embed *discordgo.MessageEmbed) (*discordgo.Message, error)

ReplyWithEmbed is shorthand to send a message to the channel the command was invoked from, with an embed.

Jump to

Keyboard shortcuts

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