discord

package
v0.1.2 Latest Latest
Warning

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

Go to latest
Published: Feb 10, 2026 License: GPL-3.0 Imports: 8 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Commands

func Commands() []*discordgo.ApplicationCommand

Commands returns the slash command definitions for the bot.

Types

type Bot

type Bot interface {
	Start(ctx context.Context) error
	Stop() error
	SendMessage(ctx context.Context, msg *OutgoingMessage) error
	SendTyping(ctx context.Context, channelID string) error
	RegisterCommands(ctx context.Context) error
	RemoveCommands(ctx context.Context) error
	OnMessage(handler MessageHandler)
	OnInteraction(handler InteractionHandler)
	BotUserID() string
}

Bot defines the interface for a Discord bot.

type DiscordBot

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

DiscordBot implements Bot using discordgo.

func NewBot

func NewBot(session DiscordSession, appID string, logger *slog.Logger) *DiscordBot

NewBot creates a new DiscordBot with the given session, app ID, and logger.

func (*DiscordBot) BotUserID

func (b *DiscordBot) BotUserID() string

BotUserID returns the bot's Discord user ID.

func (*DiscordBot) CreateChannel

func (b *DiscordBot) CreateChannel(ctx context.Context, guildID, name string) (string, error)

CreateChannel creates a new text channel in the given guild.

func (*DiscordBot) OnInteraction

func (b *DiscordBot) OnInteraction(handler InteractionHandler)

OnInteraction registers a handler to be called for slash command interactions.

func (*DiscordBot) OnMessage

func (b *DiscordBot) OnMessage(handler MessageHandler)

OnMessage registers a handler to be called for incoming messages.

func (*DiscordBot) RegisterCommands

func (b *DiscordBot) RegisterCommands(ctx context.Context) error

RegisterCommands registers the bot's slash commands with Discord.

func (*DiscordBot) RemoveCommands

func (b *DiscordBot) RemoveCommands(ctx context.Context) error

RemoveCommands removes all registered slash commands from Discord.

func (*DiscordBot) SendMessage

func (b *DiscordBot) SendMessage(ctx context.Context, msg *OutgoingMessage) error

SendMessage sends one or more messages to Discord, splitting at the 2000 char limit. If there is a pending slash command interaction for the channel, it resolves the deferred response instead of sending a regular message.

func (*DiscordBot) SendTyping

func (b *DiscordBot) SendTyping(ctx context.Context, channelID string) error

SendTyping sends a typing indicator that refreshes every 8 seconds until the context is cancelled.

func (*DiscordBot) Start

func (b *DiscordBot) Start(ctx context.Context) error

Start opens the Discord session and resolves the bot user ID.

func (*DiscordBot) Stop

func (b *DiscordBot) Stop() error

Stop closes the Discord session and removes event handlers.

type DiscordSession

type DiscordSession interface {
	Open() error
	Close() error
	AddHandler(handler any) func()
	User(userID string, options ...discordgo.RequestOption) (*discordgo.User, error)
	ChannelMessageSend(channelID string, content string, options ...discordgo.RequestOption) (*discordgo.Message, error)
	ChannelMessageSendReply(channelID string, content string, reference *discordgo.MessageReference, options ...discordgo.RequestOption) (*discordgo.Message, error)
	ChannelTyping(channelID string, options ...discordgo.RequestOption) error
	ApplicationCommandCreate(appID string, guildID string, cmd *discordgo.ApplicationCommand, options ...discordgo.RequestOption) (*discordgo.ApplicationCommand, error)
	ApplicationCommands(appID string, guildID string, options ...discordgo.RequestOption) ([]*discordgo.ApplicationCommand, error)
	ApplicationCommandDelete(appID string, guildID string, cmdID string, options ...discordgo.RequestOption) error
	InteractionRespond(interaction *discordgo.Interaction, resp *discordgo.InteractionResponse, options ...discordgo.RequestOption) error
	InteractionResponseEdit(interaction *discordgo.Interaction, newresp *discordgo.WebhookEdit, options ...discordgo.RequestOption) (*discordgo.Message, error)
	FollowupMessageCreate(interaction *discordgo.Interaction, wait bool, data *discordgo.WebhookParams, options ...discordgo.RequestOption) (*discordgo.Message, error)
	GuildChannelCreate(guildID string, name string, ctype discordgo.ChannelType, options ...discordgo.RequestOption) (*discordgo.Channel, error)
}

DiscordSession abstracts the discordgo.Session methods used by the bot, enabling test mocking.

type IncomingMessage

type IncomingMessage = orchestrator.IncomingMessage

IncomingMessage is an alias for orchestrator.IncomingMessage.

type InteractionHandler

type InteractionHandler = func(ctx context.Context, i any)

InteractionHandler is a callback for slash command interactions.

type MessageHandler

type MessageHandler = func(ctx context.Context, msg *IncomingMessage)

MessageHandler is a callback for incoming messages.

type OutgoingMessage

type OutgoingMessage = orchestrator.OutgoingMessage

OutgoingMessage is an alias for orchestrator.OutgoingMessage.

Jump to

Keyboard shortcuts

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