discord

package
v0.1.21 Latest Latest
Warning

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

Go to latest
Published: Feb 13, 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 ChannelDeleteHandler added in v0.1.12

type ChannelDeleteHandler = func(ctx context.Context, channelID string, isThread bool)

ChannelDeleteHandler is a callback for channel/thread deletion events.

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. If a text channel with the same name already exists, it returns the existing channel's ID.

func (*DiscordBot) CreateThread added in v0.1.11

func (b *DiscordBot) CreateThread(ctx context.Context, channelID, name, mentionUserID, message string) (string, error)

CreateThread creates a new public thread in the given channel and sends an initial message mentioning the bot so users know it's active. If mentionUserID is non-empty, the user is also mentioned in the greeting.

func (*DiscordBot) DeleteThread added in v0.1.14

func (b *DiscordBot) DeleteThread(ctx context.Context, threadID string) error

DeleteThread deletes a Discord thread by its ID.

func (*DiscordBot) GetChannelParentID added in v0.1.9

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

GetChannelParentID returns the parent channel ID for a thread, or empty string if not a thread.

func (*DiscordBot) GetOwnerUserID added in v0.1.20

func (b *DiscordBot) GetOwnerUserID(_ context.Context) (string, error)

GetOwnerUserID is a no-op for Discord — channels are visible to all guild members.

func (*DiscordBot) InviteUserToChannel added in v0.1.18

func (b *DiscordBot) InviteUserToChannel(_ context.Context, _, _ string) error

InviteUserToChannel is a no-op for Discord since channels are visible to all guild members.

func (*DiscordBot) OnChannelDelete added in v0.1.12

func (b *DiscordBot) OnChannelDelete(handler ChannelDeleteHandler)

OnChannelDelete registers a handler to be called when a channel or thread is deleted.

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) PostMessage added in v0.1.15

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

PostMessage sends a simple message to the given channel or thread. Text mentions of the bot (e.g. @LoopBot) are converted to proper Discord mentions so the message triggers bot processing in the target channel.

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) SetChannelTopic added in v0.1.21

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

SetChannelTopic sets the topic/description of a Discord channel.

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)
	Channel(channelID string, options ...discordgo.RequestOption) (*discordgo.Channel, 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)
	ThreadStart(channelID string, name string, typ discordgo.ChannelType, archiveDuration int, options ...discordgo.RequestOption) (*discordgo.Channel, error)
	ThreadJoin(id string, options ...discordgo.RequestOption) error
	ChannelDelete(channelID string, options ...discordgo.RequestOption) (*discordgo.Channel, error)
	GuildChannels(guildID string, options ...discordgo.RequestOption) ([]*discordgo.Channel, error)
	ChannelEdit(channelID string, data *discordgo.ChannelEdit, 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