godiscordbot

package module
v0.0.0-...-52445cd Latest Latest
Warning

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

Go to latest
Published: Jan 6, 2023 License: Apache-2.0 Imports: 4 Imported by: 0

README

Go

go-discord-bot

A framework built upon https://github.com/bwmarrin/discordgo that is meant to expedite bot development with codified patterns for leveraging Discord's Chat API features.

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type DiscordBot

type DiscordBot struct {

	// Configurations
	GuildID string

	// Legacy Commands
	LegacyCommandDeletionTimeout time.Duration
	LegacyCommandResponseTimeout time.Duration
	LegacyCommandPrefix          string

	// Slash Commands
	RegisterSlashCommands       bool
	UnregisterSlashCommands     bool
	SlashCommandResponseTimeout time.Duration
	// contains filtered or unexported fields
}

func New

func New(options Options) (*DiscordBot, error)

func (*DiscordBot) DeleteMessageWithTimeout

func (d *DiscordBot) DeleteMessageWithTimeout(channelID, messageID string, timeout time.Duration)

Delete a message from a channel after a duration

func (*DiscordBot) InteractionRespond

func (d *DiscordBot) InteractionRespond(interaction *discordgo.Interaction, resp *discordgo.InteractionResponse) error

func (*DiscordBot) LoadModule

func (d *DiscordBot) LoadModule(module Module)

LoadModule is a helper to map any handlers defined by a module

func (*DiscordBot) MapLegacyCommands

func (d *DiscordBot) MapLegacyCommands(commands map[string]func(d *DiscordBot, m *discordgo.MessageCreate, arguments []string))

Map slash command handlers for their alias

func (*DiscordBot) MapMessageComponentHandlers

func (d *DiscordBot) MapMessageComponentHandlers(handlers map[string]func(d *DiscordBot, i *discordgo.InteractionCreate))

Map message component handlers for their alias

func (*DiscordBot) MapSlashCommands

func (d *DiscordBot) MapSlashCommands(commands map[*discordgo.ApplicationCommand]func(d *DiscordBot, i *discordgo.InteractionCreate))

Map slash command handlers for their alias

func (*DiscordBot) SendMessageEmbedWithDeletionTimeout

func (d *DiscordBot) SendMessageEmbedWithDeletionTimeout(channelID string, embed *discordgo.MessageEmbed, timeout time.Duration) error

Send an embed message with content to the specified channel ID that will automatically delete itself after the timeout

func (*DiscordBot) SendMessageWithDeletionTimeout

func (d *DiscordBot) SendMessageWithDeletionTimeout(channelID string, content string, timeout time.Duration) error

Send a message with content to the specified channel ID that will automatically delete itself after the timeout

func (*DiscordBot) Start

func (d *DiscordBot) Start() error

func (*DiscordBot) Stop

func (d *DiscordBot) Stop() error

type Module

type Module interface {
	GetLegacyCommandHandlers() map[string]func(d *DiscordBot, m *discordgo.MessageCreate, arguments []string)
	GetSlashCommandHandlers() map[*discordgo.ApplicationCommand]func(d *DiscordBot, i *discordgo.InteractionCreate)
	GetMessageComponentHandlers() map[string]func(d *DiscordBot, i *discordgo.InteractionCreate)
}

Module defines the different handlers that a discord bot feature would implement

type Options

type Options struct {
	// Token to authenticate the bot with the Discord API
	DiscordToken string
	// Unused
	GuildID string

	// Any intents necessary for the bot to operate
	// * discordgo.IntentsGuildMessages - required for the bot to process legacy commands
	// * discordgo.IntentsGuildVoiceStates - required for the bot to join voice channels and play audio
	Intents discordgo.Intent

	// Legacy Commands
	// The timeout before deleting user messages (empty or zero means messages are never deleted)
	LegacyCommandDeletionTimeout time.Duration
	// The timeout before deleting bot responses (empty or zero means messages are never deleted)
	LegacyCommandResponseTimeout time.Duration
	// Prefix for legacy commands, such as "!"
	LegacyCommandPrefix string

	// Slash Commands
	// Whether or not to register slash commands when starting the bot
	RegisterSlashCommands bool
	// Whether or not to unregister slash commands when starting the bot
	UnregisterSlashCommands bool
	// The timeout before deleting bot responses (empty or zero means messages are never deleted)
	SlashCommandResponseTimeout time.Duration
}

Directories

Path Synopsis
examples

Jump to

Keyboard shortcuts

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