Documentation
¶
Index ¶
- func Commands() []*discordgo.ApplicationCommand
- type Bot
- type DiscordBot
- func (b *DiscordBot) BotUserID() string
- func (b *DiscordBot) CreateChannel(ctx context.Context, guildID, name string) (string, error)
- func (b *DiscordBot) CreateSimpleThread(ctx context.Context, channelID, name, initialMessage string) (string, error)
- func (b *DiscordBot) CreateThread(ctx context.Context, channelID, name, mentionUserID, message string) (string, error)
- func (b *DiscordBot) DeleteThread(ctx context.Context, threadID string) error
- func (b *DiscordBot) GetChannelName(_ context.Context, channelID string) (string, error)
- func (b *DiscordBot) GetChannelParentID(ctx context.Context, channelID string) (string, error)
- func (b *DiscordBot) GetMemberRoles(_ context.Context, guildID, userID string) ([]string, error)
- func (b *DiscordBot) GetOwnerUserID(_ context.Context) (string, error)
- func (b *DiscordBot) InviteUserToChannel(_ context.Context, _, _ string) error
- func (b *DiscordBot) OnChannelDelete(handler bot.ChannelDeleteHandler)
- func (b *DiscordBot) OnChannelJoin(handler bot.ChannelJoinHandler)
- func (b *DiscordBot) OnInteraction(handler bot.InteractionHandler)
- func (b *DiscordBot) OnMessage(handler bot.MessageHandler)
- func (b *DiscordBot) PostMessage(ctx context.Context, channelID, content string) error
- func (b *DiscordBot) RegisterCommands(ctx context.Context) error
- func (b *DiscordBot) RemoveCommands(ctx context.Context) error
- func (b *DiscordBot) RemoveStopButton(_ context.Context, channelID, messageID string) error
- func (b *DiscordBot) RenameThread(ctx context.Context, threadID, name string) error
- func (b *DiscordBot) SendMessage(ctx context.Context, msg *bot.OutgoingMessage) error
- func (b *DiscordBot) SendStopButton(_ context.Context, channelID, runID string) (string, error)
- func (b *DiscordBot) SendTyping(ctx context.Context, channelID string) error
- func (b *DiscordBot) SetChannelTopic(ctx context.Context, channelID, topic string) error
- func (b *DiscordBot) Start(ctx context.Context) error
- func (b *DiscordBot) Stop() error
- type DiscordSession
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 *bot.OutgoingMessage) error
SendTyping(ctx context.Context, channelID string) error
RegisterCommands(ctx context.Context) error
RemoveCommands(ctx context.Context) error
OnMessage(handler bot.MessageHandler)
OnInteraction(handler bot.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 ¶
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) CreateSimpleThread ¶ added in v0.1.31
func (b *DiscordBot) CreateSimpleThread(ctx context.Context, channelID, name, initialMessage string) (string, error)
CreateSimpleThread creates a new thread with a plain initial message (no bot mention). Returns the thread channel 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) GetChannelName ¶ added in v0.1.22
GetChannelName returns the name of a Discord channel by its ID.
func (*DiscordBot) GetChannelParentID ¶ added in v0.1.9
GetChannelParentID returns the parent channel ID for a thread, or empty string if not a thread.
func (*DiscordBot) GetMemberRoles ¶ added in v0.1.41
GetMemberRoles returns the role IDs of a guild member.
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 bot.ChannelDeleteHandler)
OnChannelDelete registers a handler to be called when a channel or thread is deleted.
func (*DiscordBot) OnChannelJoin ¶ added in v0.1.22
func (b *DiscordBot) OnChannelJoin(handler bot.ChannelJoinHandler)
OnChannelJoin registers a handler for channel join events. Discord has no equivalent "bot added to channel" event (bot sees all guild channels), so handlers are stored but never dispatched.
func (*DiscordBot) OnInteraction ¶
func (b *DiscordBot) OnInteraction(handler bot.InteractionHandler)
OnInteraction registers a handler to be called for slash command interactions.
func (*DiscordBot) OnMessage ¶
func (b *DiscordBot) OnMessage(handler bot.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) RemoveStopButton ¶ added in v0.1.42
func (b *DiscordBot) RemoveStopButton(_ context.Context, channelID, messageID string) error
RemoveStopButton deletes the stop button message.
func (*DiscordBot) RenameThread ¶ added in v0.1.49
func (b *DiscordBot) RenameThread(ctx context.Context, threadID, name string) error
RenameThread renames a Discord thread by its ID.
func (*DiscordBot) SendMessage ¶
func (b *DiscordBot) SendMessage(ctx context.Context, msg *bot.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) SendStopButton ¶ added in v0.1.42
SendStopButton sends a message with a "Stop" button that can cancel the active run.
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)
GuildMember(guildID string, userID string, options ...discordgo.RequestOption) (*discordgo.Member, error)
ChannelMessageSendComplex(channelID string, data *discordgo.MessageSend, options ...discordgo.RequestOption) (*discordgo.Message, error)
ChannelMessageDelete(channelID string, messageID string, options ...discordgo.RequestOption) error
}
DiscordSession abstracts the discordgo.Session methods used by the bot, enabling test mocking.