ktncordgo

package module
v0.1.1 Latest Latest
Warning

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

Go to latest
Published: Oct 2, 2025 License: MIT Imports: 6 Imported by: 0 modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

README

ktncord-go

Abstraction Wrapper of the discordgo Go Discord implementation.

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type DiscordAllowedMentions

type DiscordAllowedMentions struct {
	Roles       []string
	Users       []string
	Replieduser bool
}

func (*DiscordAllowedMentions) Build

Build turns DiscordAllowedMentions into discordgo.MessageAllowedMentions.

type DiscordAttachment

type DiscordAttachment struct {
	Name   string
	Source io.Reader
}

func (*DiscordAttachment) Build

func (self *DiscordAttachment) Build() *discordgo.File

Build turns DiscordAttachment into discordgo.File.

type DiscordChannelUnit

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

DiscordChannelUnit is the wrapper for the Channel object

func (*DiscordChannelUnit) Discord

func (self *DiscordChannelUnit) Discord() IDiscordUnit

Discord returns the parent DiscordUnit object, the root of ktncordgo.

func (*DiscordChannelUnit) FetchMessage

func (self *DiscordChannelUnit) FetchMessage(messageId string) (IDiscordMessageUnit, error)

FetchMessage finds and returns a single message sent in the channel.

Parameters:

messageId - The ID of the message to look for.

Returns the DiscordMessageUnit of the message if found, otherwise an error.

See: DiscordMessageUnit

func (*DiscordChannelUnit) FetchMessages

func (self *DiscordChannelUnit) FetchMessages(limit int) ([]IDiscordMessageUnit, error)

FetchMessages finds and returns the latest X messages in the channel.

Parameters:

limit - The amount of channels to find. Min: 1. Max: 100.

Returns a slice of the found messages on success, otherwise an error.

See: DiscordMessageUnit

func (*DiscordChannelUnit) Flags

Flags returns the flags of the channel.

See: discordgo.ChannelFlags

func (*DiscordChannelUnit) GetLastMessage

func (self *DiscordChannelUnit) GetLastMessage() (IDiscordMessageUnit, error)

GetLastMassage finds and returns the latest message in the channel.

Returns the message if found, otherwise an error.

See: DiscordMessageUnit

func (*DiscordChannelUnit) Guild

func (self *DiscordChannelUnit) Guild() (IDiscordGuildUnit, error)

Guild returns the Guild that the current channel is in.

See: DiscordGuildUnit

func (*DiscordChannelUnit) Id

func (self *DiscordChannelUnit) Id() string

Id returns the ID of the discord channel.

See: DiscordChannelUnit.Snowflake

func (*DiscordChannelUnit) NSFW

func (self *DiscordChannelUnit) NSFW() bool

NSFW returns true if the channel is marked as a NSFW channel.

func (*DiscordChannelUnit) Name

func (self *DiscordChannelUnit) Name() string

Name returns the name of the current channel.

func (*DiscordChannelUnit) Native

func (self *DiscordChannelUnit) Native() *discordgo.Channel

Native returns the underlying discordgo.Channel object.

func (*DiscordChannelUnit) Position

func (self *DiscordChannelUnit) Position() int

Position returns the position of the current channel in the channel list.

func (*DiscordChannelUnit) SendMessage

func (self *DiscordChannelUnit) SendMessage(message string) (IDiscordMessageUnit, error)

SendMessage sends a message in the channel.

Parameters:

message - The content of the message to send.

Returns the sent message on success, otherwise an error.

See: DiscordMessageUnit

func (*DiscordChannelUnit) SendMessageOptions

func (self *DiscordChannelUnit) SendMessageOptions(options DiscordMessageSend) (IDiscordMessageUnit, error)

SendMessageOptions sends a message in the channel with options.

Parameters:

options - The message options for the message to send.

Returns the sent message on success, otherwise an error.

See: DiscordMessageUnit

func (*DiscordChannelUnit) SendTyping

func (self *DiscordChannelUnit) SendTyping() error

SendTyping sends the typing animation to users in the channel.

Returns an error on failure.

func (*DiscordChannelUnit) Snowflake

func (self *DiscordChannelUnit) Snowflake() string

Snowflake returns the ID of the discord channel.

func (*DiscordChannelUnit) Topic

func (self *DiscordChannelUnit) Topic() string

Topic returns the topic of the current channel.

func (*DiscordChannelUnit) Type

Type returns the type of the channel.

See: discordgo.ChannelType

type DiscordEmbed

type DiscordEmbed struct {
	URL         string
	Title       string
	Description string
	Timestamp   *time.Time
	Color       int
	Footer      *DiscordEmbedFooter
	Image       *DiscordEmbedImage
	Fields      []*DiscordEmbedField
}

func (*DiscordEmbed) Build

func (self *DiscordEmbed) Build() *discordgo.MessageEmbed

Build turns DiscordEmbed into discordgo.MessageEmbed.

type DiscordEmbedField

type DiscordEmbedField struct {
	Name   string
	Value  string
	Inline bool
}

func (*DiscordEmbedField) Build

Build turns DiscordEmbedField into discordgo.MessageEmbedField.

type DiscordEmbedFooter

type DiscordEmbedFooter struct {
	Text    string
	IconURL string
}

func (*DiscordEmbedFooter) Build

Build turns DiscordEmbedFooter into discordgo.MessageEmbedFooter.

type DiscordEmbedImage

type DiscordEmbedImage struct {
	URL string
}

func (*DiscordEmbedImage) Build

Build turns DiscordEmbedImage into discordgo.MessageEmbedImage.

type DiscordGuildUnit

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

DiscordGuildUnit is the wrapper for the Guild object

func (*DiscordGuildUnit) Description

func (self *DiscordGuildUnit) Description() string

func (*DiscordGuildUnit) Discord

func (self *DiscordGuildUnit) Discord() IDiscordUnit

func (*DiscordGuildUnit) GetChannel

func (self *DiscordGuildUnit) GetChannel(channelId string) (IDiscordChannelUnit, error)

func (*DiscordGuildUnit) GetChannels

func (self *DiscordGuildUnit) GetChannels() ([]IDiscordChannelUnit, error)

func (*DiscordGuildUnit) GetMemberCount

func (self *DiscordGuildUnit) GetMemberCount() (int, error)

func (*DiscordGuildUnit) Icon

func (self *DiscordGuildUnit) Icon() string

func (*DiscordGuildUnit) Id

func (self *DiscordGuildUnit) Id() string

func (*DiscordGuildUnit) IsOwner

func (self *DiscordGuildUnit) IsOwner() bool

func (*DiscordGuildUnit) Name

func (self *DiscordGuildUnit) Name() string

func (*DiscordGuildUnit) Native

func (self *DiscordGuildUnit) Native() *discordgo.Guild

func (*DiscordGuildUnit) Region

func (self *DiscordGuildUnit) Region() string

func (*DiscordGuildUnit) Snowflake

func (self *DiscordGuildUnit) Snowflake() string

type DiscordInteractionUnit

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

DiscordInteractionUnit holds any interaction related functionality, typically seen with interaction events, like slash commands.

func (*DiscordInteractionUnit) CommandName

func (self *DiscordInteractionUnit) CommandName() string

CommandName returns the name/label of the slash command.

func (*DiscordInteractionUnit) DeferReply

func (self *DiscordInteractionUnit) DeferReply() error

DeferReply defers the reply, giving more time before replying to the command.

Typically discord requires a response within 3 seconds. Defer allows a delay of this. This cannot be followed by a [Reply] call and instead requires a [EditReply] call to follow up.

Returns an error on failure.

func (*DiscordInteractionUnit) Discord

func (self *DiscordInteractionUnit) Discord() IDiscordUnit

Discord returns the parent DiscordUnit object, the root of ktncordgo.

func (*DiscordInteractionUnit) DispatchEvent

func (self *DiscordInteractionUnit) DispatchEvent(name string, callback IDiscordCommandFn) bool

DispatchEvent matches the command name to a provided value, and if valid runs a provided callback.

Parameters:

name - The name of the command to test against.
callback - The command handler for the given command.

Returns true if the command matched.

See: IDiscordCommandFn

func (*DiscordInteractionUnit) EditReply

func (self *DiscordInteractionUnit) EditReply(message *string) error

EditReply edits the interaction reply, or sends it if [DeferReply] was used.

Parameters:

message - Reference to the new content to use when editing response.

Returns an error on failure.

func (*DiscordInteractionUnit) IsCommandName

func (self *DiscordInteractionUnit) IsCommandName(name string) bool

IsCommandName returns true if the name/label of the slash command matches a provided value.

Parameters:

name - The name of the command to test against.

Returns true if the command name matches.

func (*DiscordInteractionUnit) Native

Native returns the underlying [discorgo.User] object.

func (*DiscordInteractionUnit) Reply

func (self *DiscordInteractionUnit) Reply(message string) error

Reply sends a reply to user interaction. This cannot be used with [DeferReply].

Parameters:

message - The text to include in the interaction response.

Returns an error on failure.

func (*DiscordInteractionUnit) User added in v0.1.0

User returns the DiscordUserUnit instance of the command sender.

type DiscordMentionType

type DiscordMentionType string
const (
	DiscordMentionTypeRoles    DiscordMentionType = "roles"
	DiscordMentionTypeUsers    DiscordMentionType = "users"
	DiscordMentionTypeEveryone DiscordMentionType = "everyone"
)

type DiscordMessageEdit

type DiscordMessageEdit struct {
	Content *string

	AllowedMentions *DiscordAllowedMentions
	// contains filtered or unexported fields
}

DiscordMessageEdit contains options used for DiscordMessageUnit.EditOptions.

func (*DiscordMessageEdit) Build

func (self *DiscordMessageEdit) Build() *discordgo.MessageEdit

Build turns DiscordMessageEdit into discordgo.MessageEdit.

type DiscordMessageSend

type DiscordMessageSend struct {
	Content         string
	Embeds          []*DiscordEmbed
	TTS             bool
	Attachments     []*DiscordAttachment
	AllowedMentions *DiscordAllowedMentions
	Reference       IDiscordMessageUnit
}

DiscordMessageSend contains options used for DiscordChannelUnit.SendMessageOptions.

func (*DiscordMessageSend) Build

func (self *DiscordMessageSend) Build() *discordgo.MessageSend

Build turns DiscordMessageSend into discordgo.MessageSend.

type DiscordMessageUnit

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

DiscordMessageUnit is the wrapper for the Message object

func (*DiscordMessageUnit) Author

func (self *DiscordMessageUnit) Author() IDiscordUserUnit

Author returns the sender of the message.

See: DiscordUserUnit

func (*DiscordMessageUnit) Channel

func (self *DiscordMessageUnit) Channel() IDiscordChannelUnit

Channel returns the channel the message was sent in.

See: DiscordChannelUnit

func (*DiscordMessageUnit) Content added in v0.1.0

func (self *DiscordMessageUnit) Content() string

Content returns the text content of the message.

func (*DiscordMessageUnit) Crosspost

func (self *DiscordMessageUnit) Crosspost() error

Crosspost performs a crosspost for the message. This only works in announcement type discord channels.

Returns an error upon failure.

func (*DiscordMessageUnit) Delete

func (self *DiscordMessageUnit) Delete() error

Delete deletes the current message. This requires permission to manage messages or that the underlying DiscordUnit object user sent this message.

Returns an error upon failure.

func (*DiscordMessageUnit) Discord

func (self *DiscordMessageUnit) Discord() IDiscordUnit

Discord returns the parent DiscordUnit object, the root of ktncordgo.

func (*DiscordMessageUnit) Edit

func (self *DiscordMessageUnit) Edit(message string) error

Edit edits the message with new text. Only works if the DiscordUnit object user represent the sender of this message.

Parameter:

message - the message content to apply with the edit.

Returns an error upon failure.

func (*DiscordMessageUnit) EditOptions

func (self *DiscordMessageUnit) EditOptions(options DiscordMessageEdit) error

EditOptions edits the message with new content. Only works if the DiscordUnit object user represent the sender of this message.

Parameter:

options - the message content to apply with the edit.

Returns an error upon failure.

func (*DiscordMessageUnit) EditedTimestamp

func (self *DiscordMessageUnit) EditedTimestamp() *time.Time

EditedTimestamp returns the time.Time when the message was sent. It returns nil if the message was never edited.

func (*DiscordMessageUnit) Mentions

func (self *DiscordMessageUnit) Mentions() []IDiscordUserUnit

Mentions returns the users that have been mentioned in the message.

See: DiscordUserUnit

func (*DiscordMessageUnit) Native

func (self *DiscordMessageUnit) Native() *discordgo.Message

Native returns the underlying discordgo.Message object.

func (*DiscordMessageUnit) Reply

func (self *DiscordMessageUnit) Reply(message string) (IDiscordMessageUnit, error)

Reply replies to the message.

Parameters:

message - the message content to use in the reply.

Returns an error upon failure.

func (*DiscordMessageUnit) Timestamp

func (self *DiscordMessageUnit) Timestamp() time.Time

Timestamp returns the time.Time when the message was sent.

type DiscordUnit

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

DiscordUnit holds the main instance of ktncordgo.

func (*DiscordUnit) BotUser

func (self *DiscordUnit) BotUser() IDiscordUserUnit

BotUser gets the underlying bot user of the DiscordUnit instance.

Returns the user instance of present, otherwise nil.

See: DiscordUserUnit

func (*DiscordUnit) GetChannel added in v0.0.1

func (self *DiscordUnit) GetChannel(channelId string) (IDiscordChannelUnit, error)

GetChannel finds and returns a channel given a snowflake ID.

Parameters:

channelId - The ID of the channel to find.

Returns the channel object if found, otherwise an error.

See: DiscordChannelUnit

func (*DiscordUnit) GetGuild

func (self *DiscordUnit) GetGuild(guildId string) (IDiscordGuildUnit, error)

GetGuild finds and returns a guild given a snowflake ID.

Parameters:

guildId - The ID of the guild to find.

Returns the guild object if found, otherwise an error.

See: DiscordGuildUnit

func (*DiscordUnit) GetUser

func (self *DiscordUnit) GetUser(userId string) (IDiscordUserUnit, error)

GetUser finds and returns a user given a snowflake ID.

Parameters:

userId - The ID of the user to find.

Returns the user object if found, otherwise an error.

See: DiscordUserUnit

func (*DiscordUnit) NewInteractionUnit

func (self *DiscordUnit) NewInteractionUnit(interaction *discordgo.InteractionCreate) IDiscordInteractionUnit

NewInteractionUnit creates a new DiscordInteractionUnit reference using the current DiscordUnit instance as the parent object.

Parameters:

interaction - The underlying [discordgo.InteractionCreate] instance to use.

Returns the created DiscordInteractionUnit reference.

See: DiscordInteractionUnit

func (*DiscordUnit) OnMessageCreate

func (self *DiscordUnit) OnMessageCreate(callback func(IDiscordUnit, IDiscordMessageUnit))

OnMessageCreate registers an event handler for Channel Chat Messages.

Parameters:

callback - The callback handler for the message create event.

func (*DiscordUnit) OnSlashCommand

func (self *DiscordUnit) OnSlashCommand(callback func(IDiscordUnit, IDiscordInteractionUnit))

OnSlashCommand registers an event handler for Slash Commands.

Parameters:

callback - The callback handler for the slash command event.

func (*DiscordUnit) Session

func (self *DiscordUnit) Session() *discordgo.Session

Session returns a reference to the underlying discordgo.Session object.

Returns the discordgo.Session reference.

func (*DiscordUnit) Start

func (self *DiscordUnit) Start(commands []*discordgo.ApplicationCommand) error

Start takes a slice of commands, opens the session, and registers the commands with discord.

Parameters:

commands - a slice of [discordgo.ApplicationCommand] references.

Returns an error on failure.

func (*DiscordUnit) Stop

func (self *DiscordUnit) Stop()

Stop stops the discord session.

type DiscordUserUnit

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

DiscordUserUnit is the wrapper for the User object

func (*DiscordUserUnit) Discord

func (self *DiscordUserUnit) Discord() IDiscordUnit

Discord gets the parent DiscordUnit object, the root of ktncordgo.

func (*DiscordUserUnit) Discriminator

func (self *DiscordUserUnit) Discriminator() string

Discriminator gets the 4 Discriminator digs of the discord user. This is no longer used for normal users and is limited to bots. For a normal user this will return "0000".

func (*DiscordUserUnit) GlobalName

func (self *DiscordUserUnit) GlobalName() string

GlobalName gets the global display name of the discord user.

func (*DiscordUserUnit) HasMFAEnabled

func (self *DiscordUserUnit) HasMFAEnabled() bool

HasMFAEnabled returns true if the discord user has multi-factor authentication enabled. Might not work. See discordgo.User.MFAEnabled for more info.

func (*DiscordUserUnit) Id

func (self *DiscordUserUnit) Id() string

Id gets the ID of the discord user.

See: DiscordUserUnit.Snowflake

func (*DiscordUserUnit) IsAnyNitro

func (self *DiscordUserUnit) IsAnyNitro() bool

IsAnyNitro returns true if the discord user has any of the Nitro tier, be that Nitro (9.99€), Nitro Basic (2.99€) or Nitro Classic (4.99€ mostly obsolete).

func (*DiscordUserUnit) IsBot

func (self *DiscordUserUnit) IsBot() bool

IsBot returns true if the discord user is a bot.

func (*DiscordUserUnit) IsNitro

func (self *DiscordUserUnit) IsNitro() bool

IsNitro returns true if the discord user has Nitro (9.99€).

func (*DiscordUserUnit) IsNitroBasic

func (self *DiscordUserUnit) IsNitroBasic() bool

IsNitroBasic returns true if the discord user has Nitro Basic (2.99€).

func (*DiscordUserUnit) IsNitroClassic

func (self *DiscordUserUnit) IsNitroClassic() bool

IsNitroClassic returns true if the discord user has Nitro Classic (4.99€ mostly obsolete).

func (*DiscordUserUnit) IsSystem

func (self *DiscordUserUnit) IsSystem() bool

IsSystem returns true if the discord user is a system user, typically seen with Discord's own announcement messages.

func (*DiscordUserUnit) IsVerified

func (self *DiscordUserUnit) IsVerified() bool

IsVerified returns true if the discord user has verified their email. Might not work. See discordgo.User.Verified for more info.

func (*DiscordUserUnit) Native

func (self *DiscordUserUnit) Native() *discordgo.User

Native gets the underlying discordgo.User object.

func (*DiscordUserUnit) Snowflake

func (self *DiscordUserUnit) Snowflake() string

Snowflake gets the ID of the discord user.

func (*DiscordUserUnit) Username

func (self *DiscordUserUnit) Username() string

Username gets the username of the discord user.

type IDiscordChannelUnit

type IDiscordChannelUnit interface {
	Discord() IDiscordUnit
	Native() *discordgo.Channel

	// Base
	Snowflake() string
	Id() string

	// Information
	Guild() (IDiscordGuildUnit, error)
	Name() string
	Topic() string
	Position() int

	NSFW() bool

	Type() discordgo.ChannelType
	Flags() discordgo.ChannelFlags

	// Methods
	FetchMessage(string) (IDiscordMessageUnit, error)
	FetchMessages(limit int) ([]IDiscordMessageUnit, error)
	GetLastMessage() (IDiscordMessageUnit, error)
	SendMessage(string) (IDiscordMessageUnit, error)
	SendMessageOptions(options DiscordMessageSend) (IDiscordMessageUnit, error)

	SendTyping() error
}

IDiscordChannelUnit is the channel interface.

See: DiscordChannelUnit

type IDiscordCommandFn

type IDiscordCommandFn func(IDiscordInteractionUnit) error

IDiscordCommandFn is a slash command handler callback function definition.

type IDiscordGuildUnit

type IDiscordGuildUnit interface {
	Discord() IDiscordUnit
	Native() *discordgo.Guild

	// Base
	Snowflake() string
	Id() string

	// Information
	Name() string
	Description() string
	Icon() string
	Region() string

	IsOwner() bool

	// Methods
	GetChannels() ([]IDiscordChannelUnit, error)
	GetChannel(string) (IDiscordChannelUnit, error)

	GetMemberCount() (int, error)
}

IDiscordGuildUnit is the guild interface.

See: DiscordGuildUnit

type IDiscordInteractionUnit

type IDiscordInteractionUnit interface {
	Discord() IDiscordUnit
	Native() *discordgo.InteractionCreate

	User() IDiscordUserUnit

	DeferReply() error
	Reply(message string) error
	EditReply(message *string) error

	CommandName() string
	IsCommandName(name string) bool
	DispatchEvent(name string, callback IDiscordCommandFn) bool
}

IDiscordInteractionUnit is the slash command interaction interface.

See: DiscordInteractionUnit

type IDiscordMessageUnit

type IDiscordMessageUnit interface {
	Discord() IDiscordUnit
	Native() *discordgo.Message

	Channel() IDiscordChannelUnit
	Content() string

	Author() IDiscordUserUnit
	Timestamp() time.Time
	EditedTimestamp() *time.Time
	Mentions() []IDiscordUserUnit

	Edit(message string) error
	EditOptions(options DiscordMessageEdit) error
	Crosspost() error
	Delete() error

	Reply(message string) (IDiscordMessageUnit, error)
}

IDiscordMessageUnit is the message interface.

See: DiscordMessageUnit

type IDiscordUnit

type IDiscordUnit interface {
	Session() *discordgo.Session
	NewInteractionUnit(interaction *discordgo.InteractionCreate) IDiscordInteractionUnit

	OnSlashCommand(func(IDiscordUnit, IDiscordInteractionUnit))
	OnMessageCreate(func(IDiscordUnit, IDiscordMessageUnit))

	Start([]*discordgo.ApplicationCommand) error
	Stop()

	GetUser(string) (IDiscordUserUnit, error)
	GetChannel(string) (IDiscordChannelUnit, error)
	GetGuild(string) (IDiscordGuildUnit, error)

	BotUser() IDiscordUserUnit
}

IDiscordUnit is the root ktncordgo interface.

See: DiscordUnit

func CreateDiscordUnit

func CreateDiscordUnit(token string) (IDiscordUnit, error)

CreateDiscordUnit takes a discord token and creates a DiscordUnit instance.

Returns the create instance on success, otherwise an error.

func NewDiscordUnit

func NewDiscordUnit(session *discordgo.Session) IDiscordUnit

NewDiscordUnit takes a discordgo.Session reference and creates a DiscordUnit.

Parameters:

session - The underlying [discordgo.Session] reference to use.

Returns the created DiscordUnit reference.

type IDiscordUserUnit

type IDiscordUserUnit interface {
	Discord() IDiscordUnit
	Native() *discordgo.User

	// Base
	Snowflake() string
	Id() string

	// Information
	Username() string
	Discriminator() string
	GlobalName() string

	IsBot() bool
	IsVerified() bool
	HasMFAEnabled() bool

	IsSystem() bool

	IsAnyNitro() bool
	IsNitroClassic() bool
	IsNitroBasic() bool
	IsNitro() bool
}

IDiscordUserUnit is the user interface.

See: DiscordUserUnit

Jump to

Keyboard shortcuts

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