corde

package module
v0.9.0 Latest Latest
Warning

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

Go to latest
Published: Jan 8, 2024 License: MIT Imports: 16 Imported by: 0

README

                        _       
                       | |      
  ___   ___   _ __   __| |  ___ 
 / __| / _ \ | '__| / _` | / _ \
| (__ | (_) || |   | (_| ||  __/
 \___| \___/ |_|    \__,_| \___|
                                

report card badge


corde is a discord webhook callback API wrapper. It aims to have an high level API to simplify the user's life as much as possible.

It contains many functions to help write as clean and concise code as possible, such as f suffixed functions which act like Sprintf.

It also has builders of some kinds, such as embed and response builders, which make error handling and responding a breeze.

All those don't hinder the fact that you can use corde with as much control as you want.

Be aware that breaking changes will happen as of now, at least until v1.

Install

go get github.com/Karitham/corde
Usage

The easiest way to run the examples, or even to run your own is to use ngrok no login or domain required, and the product itself is great.

Examples

The most basic one is bongo

Then comes todo that shows off subcommands routing and options

And then we have moderate-myself which is able to show and delete currently available commands. It demonstrates the usage of components such as buttons.

Finally, we have nft which is a simple example using user commands & message commands.

Corde is also actively used to rewrite and develop another discord bot of mine called WaifuBot (for now see the corde branch)

Why

Having used most go discord libs available, I wanted something very lightweight yet high-level, that could just run on a lambda without state, caching or long start-up times.

Corde has a single runtime dependency as of yet, a radix tree for routing purposes (and it's epic, you should check it out).

The common libs out there didn't really fit that purpose, and neither did they implement the webhook callback API available.

Corde means rope in french, because discord's API inspires exactly that /s

Documentation

Index

Constants

View Source
const (
	// RouteInteractionSubcommandGroup represents the map key for a subcommand group route
	RouteInteractionSubcommandGroup = "$group"
	// RouteInteractionSubcommand reprensents the map key for a subcommand route
	RouteInteractionSubcommand = "$command"

	// RouteInteractionFocused represents the map key for a focused route.
	// This is useful for autocomplete interactions so we can route on focused keys
	// Such, we route on `$group/$command/$focused`,
	RouteInteractionFocused = "$focused"
)
View Source
const (
	CHANNEL_GUILD_TEXT ChannelType = iota
	CHANNEL_DM
	CHANNEL_GUILD_VOICE
	CHANNEL_GROUP_DM
	CHANNEL_GUILD_CATEGORY
	CHANNEL_GUILD_NEWS
	CHANNEL_GUILD_STORE
	CHANNEL_GUILD_NEWS_THREAD = iota + 3
	CHANNEL_GUILD_PUBLIC_THREAD
	CHANNEL_GUILD_PRIVATE_THREAD
	CHANNEL_GUILD_STAGE_VOICE
)
View Source
const (
	MESSAGE_ACTIVITY_JOIN         = 1
	MESSAGE_ACTIVITY_SPECTATE     = 2
	MESSAGE_ACTIVITY_LISTEN       = 3
	MESSAGE_ACTIVITY_JOIN_REQUEST = 5
)

https://regex101.com/r/Sj1ZLk/1

View Source
const (
	// MESSAGE_FLAG_CROSSPOSTED means this message has been published to subscribed channels (via Channel Following)
	MESSAGE_FLAG_CROSSPOSTED = 1 << 0
	// MESSAGE_FLAG_IS_CROSSPOST means this message originated from a message in another channel (via Channel Following)
	MESSAGE_FLAG_IS_CROSSPOST = 1 << 1
	// MESSAGE_FLAG_SUPPRESS_EMBEDS means do not include any embeds when serializing this message
	MESSAGE_FLAG_SUPPRESS_EMBEDS = 1 << 2
	// MESSAGE_FLAG_SOURCE_MESSAGE_DELETED means the source message for this crosspost has been deleted (via Channel Following)
	MESSAGE_FLAG_SOURCE_MESSAGE_DELETED = 1 << 3
	// MESSAGE_FLAG_URGENT means this message came from the urgent message system
	MESSAGE_FLAG_URGENT = 1 << 4
	// MESSAGE_FLAG_HAS_THREAD means this message has an associated thread, with the same id as the message
	MESSAGE_FLAG_HAS_THREAD = 1 << 5
	// MESSAGE_FLAG_EPHEMERAL means this message is only visible to the user who invoked the Interaction
	MESSAGE_FLAG_EPHEMERAL = 1 << 6
	// MESSAGE_FLAG_LOADING means this message is an Interaction Response and the bot is "thinking"
	MESSAGE_FLAG_LOADING = 1 << 7
)

https://regex101.com/r/1SsWbP/1

Variables

This section is empty.

Functions

func GuildOpt

func GuildOpt(guildID Snowflake) func(*CommandsOpt)

GuildOpt is an option for setting the guild of a Command

Types

type Activity

type Activity struct {
	Type    int    `json:"type,omitempty"`
	PartyID string `json:"party_id,omitempty"`
}

Activity https://discord.com/developers/docs/resources/channel#message-object-message-activity-structure

type AllowedMentions

type AllowedMentions struct {
	Parse []string `json:"parse"`
}

type Application

type Application struct {
	ID                  Snowflake `json:"id"`
	Name                string    `json:"name"`
	Icon                string    `json:"icon"`
	Description         string    `json:"description"`
	RPCOrigins          []string  `json:"rpc_origins,omitempty"`
	BotPublic           bool      `json:"bot_public"`
	BotRequireCodeGrant bool      `json:"bot_require_code_grant"`
	TermsOfServiceURL   string    `json:"terms_of_service_url,omitempty"`
	PrivacyPolicyURL    string    `json:"privacy_policy_url,omitempty"`
	Owner               User      `json:"owner,omitempty"`
	Summary             string    `json:"summary"`
	VerifyKey           string    `json:"verify_key"`
	Team                Team      `json:"team,omitempty"`
	GuildID             Snowflake `json:"guild_id,omitempty"`
	PrimarySKUID        Snowflake `json:"primary_sku_id,omitempty"`
	Slug                string    `json:"slug,omitempty"`
	CoverImage          string    `json:"cover_image,omitempty"`
	Flags               int       `json:"flags,omitempty"`
}

Application https://discord.com/developers/docs/resources/application#application-object-application-structure

type Attachment

type Attachment struct {
	Body        io.Reader `json:"-"`
	ID          Snowflake `json:"id"`
	Filename    string    `json:"filename"`
	Description string    `json:"description,omitempty"`
	ContentType string    `json:"content_type,omitempty"`
	Size        int       `json:"size,omitempty"`
	URL         string    `json:"url,omitempty"`
	ProxyURL    string    `json:"proxy_url,omitempty"`
	Height      int       `json:"height,omitempty"`
	Width       int       `json:"width,omitempty"`
	Ephemeral   bool      `json:"ephemeral,omitempty"`
}

Attachement is the files attached to the request

type Author

type Author struct {
	Name         string `json:"name"`
	URL          string `json:"url,omitempty"`
	IconURL      string `json:"icon_url,omitempty"`
	ProxyIconURL string `json:"proxy_icon_url,omitempty"`
}

Author is the author object

type AutocompleteInteractionData added in v0.8.0

type AutocompleteInteractionData struct {
	ID      Snowflake           `json:"id"`
	Name    string              `json:"name"`
	Type    int                 `json:"type"`
	Options OptionsInteractions `json:"options,omitempty"`
}

type BoolOption

type BoolOption struct {
	Name         string
	Description  string
	Required     bool
	Choices      []Choice[any]
	ChannelTypes []ChannelType
	Autocomplete bool
}

BoolOption represents a bool option

func NewBoolOption

func NewBoolOption(name string, description string, required bool, choices ...Choice[bool]) *BoolOption

NewBoolOption returns a new BoolOption

func (*BoolOption) ChanTypes

func (o *BoolOption) ChanTypes(typs ...ChannelType) *BoolOption

ChanTypes sets the options channel types

func (*BoolOption) MarshalJSON

func (o *BoolOption) MarshalJSON() ([]byte, error)

MarshalJSON returns the JSON representation of the option

type Button

type Button struct {
	Type     ComponentType `json:"type"`
	Style    Style         `json:"style"`
	Label    string        `json:"label,omitempty"`
	Emoji    Emoji         `json:"emoji,omitempty"`
	CustomID string        `json:"custom_id,omitempty"`
	URL      string        `json:"url,omitempty"`
	Disabled bool          `json:"disabled,omitempty"`
}

Button https://discord.com/developers/docs/interactions/message-components#button-object

type ButtonInteractionData added in v0.8.0

type ButtonInteractionData struct {
	CustomID      string        `json:"custom_id,omitempty"`
	ComponentType ComponentType `json:"component_type"`
}

type Channel

type Channel struct {
	ID                   Snowflake   `json:"id"`
	Name                 string      `json:"name"`
	Type                 ChannelType `json:"type"`
	GuildID              Snowflake   `json:"guild_id"`
	Position             int         `json:"position"`
	PermissionOverwrites []Overwrite `json:"permission_overwrites"`
	Topic                string      `json:"topic,omitempty"`
	NSFW                 bool        `json:"nsfw,omitempty"`
	LastMessageID        Snowflake   `json:"last_message_id,omitempty"`
	Bitrate              int         `json:"bitrate,omitempty"`
	UserLimit            int         `json:"user_limit,omitempty"`
	RateLimitPerUser     int         `json:"rate_limit_per_user,omitempty"`
	LastPinTimestamp     Timestamp   `json:"last_pin_timestamp,omitempty"`
	OwnerID              Snowflake   `json:"owner_id,omitempty"`
}

Channel https://discord.com/developers/docs/resources/channel#channel-object

type ChannelOption

type ChannelOption struct {
	Name         string
	Description  string
	Required     bool
	Choices      []Choice[any]
	ChannelTypes []ChannelType
	Autocomplete bool
}

ChannelOption represents a Snowflake option

func NewChannelOption

func NewChannelOption(name string, description string, required bool, choices ...Choice[Snowflake]) *ChannelOption

NewChannelOption returns a new ChannelOption

func (*ChannelOption) ChanTypes

func (o *ChannelOption) ChanTypes(typs ...ChannelType) *ChannelOption

ChanTypes sets the options channel types

func (*ChannelOption) MarshalJSON

func (o *ChannelOption) MarshalJSON() ([]byte, error)

MarshalJSON returns the JSON representation of the option

type Choice

type Choice[T any] struct {
	Name  string `json:"name"`
	Value T      `json:"value"`
}

Choice is an application Command choice

type Command

type Command struct {
	Name              string      `json:"name,omitempty"`
	ID                Snowflake   `json:"id,omitempty"`
	Type              CommandType `json:"type,omitempty"`
	ApplicationID     Snowflake   `json:"application_id,omitempty"`
	GuildID           Snowflake   `json:"guild_id,omitempty"`
	Description       string      `json:"description,omitempty"`
	Options           []Option    `json:"options,omitempty"`
	DefaultPermission bool        `json:"default_permission,omitempty"`
	Version           Snowflake   `json:"version,omitempty"`
}

Command is a Discord application command

type CommandType

type CommandType int
const (
	COMMAND_CHAT_INPUT CommandType = iota + 1
	COMMAND_USER
	COMMAND_MESSAGE
)

type CommandsOpt

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

CommandsOpt is an option for a Command

type Component

type Component struct {
	Type        ComponentType `json:"type"`
	CustomID    string        `json:"custom_id"`
	Style       Style         `json:"style,omitempty"`
	Disabled    bool          `json:"disabled,omitempty"`
	Label       string        `json:"label,omitempty"`
	Emoji       *Emoji        `json:"emoji,omitempty"`
	URL         string        `json:"url,omitempty"`
	Placeholder string        `json:"placeholder,omitempty"`
	MinValues   int           `json:"min_values,omitempty"`
	MaxValues   int           `json:"max_values,omitempty"`
	MinLength   int           `json:"min_length,omitempty"`
	MaxLength   int           `json:"max_length,omitempty"`
	Required    bool          `json:"required,omitempty"`
	Value       string        `json:"value,omitempty"`
	Options     []Option      `json:"options,omitempty"`
	Components  []Component   `json:"components,omitempty"`
}

Component

https://discord.com/developers/docs/interactions/message-components#component-object-component-types

func (Component) Component added in v0.8.0

func (c Component) Component() Component

type ComponentType

type ComponentType int

ComponentType https://discord.com/developers/docs/interactions/message-components#button-object

const (
	COMPONENT_ACTION_ROW ComponentType = iota + 1
	COMPONENT_BUTTON
	COMPONENT_SELECT_MENU
	COMPONENT_TEXT_INPUT
)

type CreateCommand

type CreateCommand struct {
	Name                      string           `json:"name,omitempty"`
	Description               string           `json:"description,omitempty"`
	Type                      CommandType      `json:"type,omitempty"`
	Options                   []CreateOptioner `json:"options,omitempty"`
	DefaultPermissionDisabled bool             `json:"default_permission"`
}

CreateCommand is a slash command that can be registered to discord

func NewMessageCommand

func NewMessageCommand(name string) CreateCommand

NewMessageCommand returns a new message command

func NewSlashCommand

func NewSlashCommand(name string, description string, options ...CreateOptioner) CreateCommand

NewSlashCommand returns a new slash command

func NewUserCommand

func NewUserCommand(name string) CreateCommand

NewUserCommand returns a new user command

func (CreateCommand) MarshalJSON

func (c CreateCommand) MarshalJSON() ([]byte, error)

MarshalJSON implements json.Marshaler

type CreateCommander

type CreateCommander interface {
	// contains filtered or unexported methods
}

CreateCommander is a command that can be registered

type CreateOption

type CreateOption struct {
	Name         string           `json:"name"`
	Type         OptionType       `json:"type"`
	Description  string           `json:"description,omitempty"`
	Required     bool             `json:"required,omitempty"`
	Choices      []Choice[any]    `json:"choices,omitempty"`
	Options      []CreateOptioner `json:"options,omitempty"`
	ChannelTypes []ChannelType    `json:"channel_types,omitempty"`
	MinValue     float64          `json:"min_value,omitempty"`
	MaxValue     float64          `json:"max_value,omitempty"`
	Autocomplete bool             `json:"autocomplete,omitempty"`
}

CreateOption is the base option type for creating any sort of option

type CreateOptioner

type CreateOptioner interface {
	// contains filtered or unexported methods
}

CreateOptioner is an interface for all options

type Embed

type Embed struct {
	Title       string     `json:"title,omitempty"`
	Description string     `json:"description,omitempty"`
	URL         string     `json:"url,omitempty"`
	Timestamp   *Timestamp `json:"timestamp,omitempty"`
	Color       uint32     `json:"color,omitempty"`
	Footer      Footer     `json:"footer,omitempty"`
	Image       Image      `json:"image,omitempty"`
	Thumbnail   Image      `json:"thumbnail,omitempty"`
	Video       Video      `json:"video,omitempty"`
	Provider    Provider   `json:"provider,omitempty"`
	Author      Author     `json:"author,omitempty"`
	Fields      []Field    `json:"fields,omitempty"`
}

Embed is the embed object https://discord.com/developers/docs/resources/channel#embed-object

func (Embed) Embed

func (e Embed) Embed() Embed

Embed implements Embedder

func (Embed) InteractionRespData

func (e Embed) InteractionRespData() *InteractionRespData

InteractionRespData implements InteractionResponder

type EmbedB

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

EmbedB is an Embed builder https://regex101.com/r/gmVH2A/4

func NewEmbed

func NewEmbed() *EmbedB

NewEmbed returns a new embed builder ready for use

func (*EmbedB) Author

func (e *EmbedB) Author(a Author) *EmbedB

Author adds the author to the Embed

func (*EmbedB) Color

func (e *EmbedB) Color(i uint32) *EmbedB

Color adds the color to the Embed

func (*EmbedB) Description

func (e *EmbedB) Description(s string) *EmbedB

Description adds the description to the Embed

func (*EmbedB) Descriptionf

func (e *EmbedB) Descriptionf(format string, a ...any) *EmbedB

Descriptionf adds the description to the Embed

func (*EmbedB) Embed

func (e *EmbedB) Embed() Embed

Embed returns the built Embed

func (*EmbedB) Field

func (e *EmbedB) Field(name, value string) *EmbedB

Field adds a field to the Embed

func (*EmbedB) FieldInline

func (e *EmbedB) FieldInline(name, value string) *EmbedB

FieldInline adds an inline field to the Embed

func (*EmbedB) Fields

func (e *EmbedB) Fields(f ...Field) *EmbedB

Fields append the field to the Embed

func (*EmbedB) Footer

func (e *EmbedB) Footer(f Footer) *EmbedB

Footer adds the footer to the Embed

func (*EmbedB) Image

func (e *EmbedB) Image(i Image) *EmbedB

Image adds the image to the Embed

func (*EmbedB) ImageURL

func (e *EmbedB) ImageURL(s string) *EmbedB

ImageURL adds an image based off the url to the Embed

func (*EmbedB) InteractionRespData

func (e *EmbedB) InteractionRespData() *InteractionRespData

InteractionRespData implements InteractionResponder

func (*EmbedB) Message added in v0.9.0

func (e *EmbedB) Message() Message

Message returns the embed wrapped in a message

func (*EmbedB) Provider

func (e *EmbedB) Provider(name string, url string) *EmbedB

Provider adds a provider to the Embed

func (*EmbedB) Thumbnail

func (e *EmbedB) Thumbnail(i Image) *EmbedB

Thumbnail adds the thumbnail to the Embed

func (*EmbedB) Timestamp

func (e *EmbedB) Timestamp(t time.Time) *EmbedB

Timestamp adds the timestamp to the Embed

func (*EmbedB) Title

func (e *EmbedB) Title(s string) *EmbedB

Title adds the title to the Embed

func (*EmbedB) Titlef

func (e *EmbedB) Titlef(format string, a ...any) *EmbedB

Titlef adds the Title to the Embed

func (*EmbedB) URL

func (e *EmbedB) URL(s string) *EmbedB

URL adds the url to the Embed

func (*EmbedB) Video

func (e *EmbedB) Video(v Video) *EmbedB

Video adds the video to the Embed

type Embedder

type Embedder interface {
	Embed() Embed
}

Embedder returns an Embed

type Emoji

type Emoji struct {
	ID            Snowflake   `json:"id,omitempty"`
	Name          string      `json:"name"`
	Roles         []Snowflake `json:"roles,omitempty"`
	User          User        `json:"user,omitempty"`
	RequireColons bool        `json:"require_colons,omitempty"`
	Managed       bool        `json:"managed,omitempty"`
	Animated      bool        `json:"animated,omitempty"`
	Available     bool        `json:"available,omitempty"`
}

Emoji https://discord.com/developers/docs/resources/emoji#emoji-object

type Field

type Field struct {
	Name   string `json:"name"`
	Value  string `json:"value"`
	Inline bool   `json:"inline,omitempty"`
}

Field is the field object inside an embed

type Footer struct {
	Text         string `json:"text"`
	IconURL      string `json:"icon_url,omitempty"`
	ProxyIconURL string `json:"proxy_icon_url,omitempty"`
}

Footer is the footer of the embed

type Handlers added in v0.8.0

type Handlers map[InnerInteractionType]any

Handlers handles incoming requests

type Hash

type Hash string

Hash is a discord profile picture hash https://discord.com/developers/docs/reference#image-formatting

func (Hash) Animated

func (h Hash) Animated() bool

Animated returns wether the url is an animated gif

type Image

type Image struct {
	URL      string `json:"url,omitempty"`
	ProxyURL string `json:"proxy_url,omitempty"`
	Height   int    `json:"height,omitempty"`
	Width    int    `json:"width,omitempty"`
}

Image is an image possibly contained inside the embed

type InnerInteractionType added in v0.8.0

type InnerInteractionType int

InnerInteractionType is the inner type of interactions, and not just command, component, autocomplete etc.

const (
	// components
	ActionRowInteraction InnerInteractionType = iota + 1
	ButtonInteraction
	SelectMenuInteraction
	TextInputInteraction

	// autocomplete
	AutocompleteInteraction

	// commands
	SlashCommandInteraction
	UserCommandInteraction
	MessageCommandInteraction

	ModalInteraction
)

type IntOption

type IntOption struct {
	Name         string
	Description  string
	Required     bool
	Choices      []Choice[any]
	ChannelTypes []ChannelType
	Autocomplete bool
}

IntOption represents a int option

func NewIntOption

func NewIntOption(name string, description string, required bool, choices ...Choice[int]) *IntOption

NewIntOption returns a new IntOption

func (*IntOption) CanAutocomplete

func (o *IntOption) CanAutocomplete() *IntOption

CanAutocomplete sets the option as autocomplete-able

func (*IntOption) ChanTypes

func (o *IntOption) ChanTypes(typs ...ChannelType) *IntOption

ChanTypes sets the options channel types

func (*IntOption) MarshalJSON

func (o *IntOption) MarshalJSON() ([]byte, error)

MarshalJSON returns the JSON representation of the option

type IntResponseFlags

type IntResponseFlags uint
const (
	RESPONSE_FLAGS_EPHEMERAL IntResponseFlags = 64
)

type Interaction

type Interaction[T InteractionDataConstraint] struct {
	ID            Snowflake       `json:"id"`
	ApplicationID Snowflake       `json:"application_id"`
	Type          InteractionType `json:"type"`
	Data          T               `json:"data,omitempty"`
	GuildID       Snowflake       `json:"guild_id,omitempty"`
	ChannelID     Snowflake       `json:"channel_id,omitempty"`
	Member        Member          `json:"member,omitempty"`
	User          *User           `json:"user,omitempty"`
	Token         string          `json:"token"`
	Version       int             `json:"version"`
	Message       *Message        `json:"message,omitempty"`
	Locale        string          `json:"locale,omitempty"`
	GuildLocale   string          `json:"guild_locale,omitempty"`

	Route                string               `json:"-"`
	InnerInteractionType InnerInteractionType `json:"-"`
}

Interaction is a Discord Interaction https://discord.com/developers/docs/interactions/receiving-and-responding#interactions

type InteractionDataConstraint added in v0.8.0

InteractionDataConstraint is the constraint for the interaction data It contains all the possible values for interaction data

type InteractionRespData

type InteractionRespData struct {
	Content         string           `json:"content,omitempty"`
	TTS             bool             `json:"tts,omitempty"`
	Embeds          []Embed          `json:"embeds,omitempty"`
	AllowedMentions *AllowedMentions `json:"allowed_mentions,omitempty"`
	Flags           IntResponseFlags `json:"flags,omitempty"`
	Components      []Component      `json:"components,omitempty"`
	Attachments     []Attachment     `json:"attachments,omitempty"`
	Choices         []Choice[any]    `json:"choices,omitempty"`
}

InteractionRespData is the payload for responding to an interaction https://discord.com/developers/docs/interactions/receiving-and-responding#interaction-response-object-interaction-callback-data-structure

func (*InteractionRespData) InteractionRespData

func (i *InteractionRespData) InteractionRespData() *InteractionRespData

InteractionRespData implements InteractionResponder interface

type InteractionResponder

type InteractionResponder interface {
	InteractionRespData() *InteractionRespData
}

InteractionResponder returns InteractionRespData

type InteractionType

type InteractionType int

InteractionType is the type of interaction

const (
	INTERACTION_TYPE_PING InteractionType = iota + 1
	INTERACTION_TYPE_APPLICATION_COMMAND
	INTERACTION_TYPE_MESSAGE_COMPONENT
	INTERACTION_TYPE_APPLICATION_COMMAND_AUTOCOMPLETE
	INTERACTION_TYPE_MODAL
)

type JsonRaw

type JsonRaw []byte

JsonRaw is a raw json value

func (JsonRaw) MarshalJSON

func (m JsonRaw) MarshalJSON() ([]byte, error)

MarshalJSON returns m as the JSON encoding of m.

func (JsonRaw) String

func (m JsonRaw) String() string

String returns the raw json as a string

func (*JsonRaw) UnmarshalJSON

func (m *JsonRaw) UnmarshalJSON(data []byte) error

UnmarshalJSON sets *m to a copy of data.

func (JsonRaw) UnmarshalTo

func (m JsonRaw) UnmarshalTo(v any) error

UnmarshalTo unmarshals the JSON-encoded data and stores the result in the value pointed to by v.

type Member

type Member struct {
	User                       User        `json:"user"`
	Nick                       string      `json:"nick,omitempty"`
	RoleIDs                    []Snowflake `json:"roles,omitempty"`
	Avatar                     Hash        `json:"avatar,omitempty"`
	Joined                     Timestamp   `json:"joined_at"`
	BoostedSince               Timestamp   `json:"premium_since,omitempty"`
	CommunicationDisabledUntil Timestamp   `json:"communication_disabled_until,omitempty"`
	Deaf                       bool        `json:"deaf,omitempty"`
	Mute                       bool        `json:"mute,omitempty"`
	IsPending                  bool        `json:"pending,omitempty"`
	Permissions                string      `json:"permissions,omitempty"`
}

Member is a Discord Member https://discord.com/developers/docs/resources/guild#guild-member-object

type MentionableOption

type MentionableOption struct {
	Name         string
	Description  string
	Required     bool
	Choices      []Choice[any]
	ChannelTypes []ChannelType
	Autocomplete bool
}

MentionableOption represents a Snowflake option

func NewMentionableOption

func NewMentionableOption(name string, description string, required bool, choices ...Choice[Snowflake]) *MentionableOption

NewMentionableOption returns a new MentionableOption

func (*MentionableOption) ChanTypes

func (o *MentionableOption) ChanTypes(typs ...ChannelType) *MentionableOption

ChanTypes sets the options channel types

func (*MentionableOption) MarshalJSON

func (o *MentionableOption) MarshalJSON() ([]byte, error)

MarshalJSON returns the JSON representation of the option

type Message

type Message struct {
	ID                Snowflake             `json:"id"`
	ChannelID         Snowflake             `json:"channel_id"`
	GuildID           Snowflake             `json:"guild_id,omitempty"`
	Author            User                  `json:"user,omitempty"`
	Member            Member                `json:"member,omitempty"`
	Content           string                `json:"content"`
	Timestamp         Timestamp             `json:"timestamp"`
	Edited            Timestamp             `json:"edited_timestamp,omitempty"`
	TTS               bool                  `json:"tts"`
	Mention           bool                  `json:"mention_everyone"`
	Mentions          []User                `json:"mentions,omitempty"`
	MentionRoles      []Snowflake           `json:"mention_roles,omitempty"`
	MentionChannels   []Channel             `json:"mention_channels,omitempty"`
	Attachments       []Attachment          `json:"attachments,omitempty"`
	Embeds            []Embed               `json:"embeds,omitempty"`
	Reactions         []Reaction            `json:"reactions,omitempty"`
	Nonce             string                `json:"nonce,omitempty"`
	Pinned            bool                  `json:"pinned,omitempty"`
	WebhookID         Snowflake             `json:"webhook_id,omitempty"`
	Type              MessageType           `json:"type"`
	Activity          *Activity             `json:"activity,omitempty"`
	Application       Application           `json:"application,omitempty"`
	ApplicationID     Snowflake             `json:"application_id,omitempty"`
	MessageReference  *MessageReference     `json:"message_reference,omitempty"`
	Flags             MessageFlag           `json:"flags,omitempty"`
	ReferencedMessage *Message              `json:"referenced_message,omitempty"`
	Interaction       *Interaction[JsonRaw] `json:"interaction,omitempty"`
	Thread            Channel               `json:"thread,omitempty"`
	Components        []Component           `json:"components,omitempty"`
	StickerItems      []StickerItem         `json:"sticker_items,omitempty"`
	Stickers          []Sticker             `json:"stickers,omitempty"`
}

Message is a Discord Message https://discord.com/developers/docs/resources/channel#message-object

type MessageCommandInteractionData added in v0.8.0

type MessageCommandInteractionData struct {
	ID       Snowflake `json:"id"`
	TargetID Snowflake `json:"target_id,omitempty"`
	Name     string    `json:"name"`
	Type     int       `json:"type"`
	// contains filtered or unexported fields
}

func (MessageCommandInteractionData) OptionsMember added in v0.8.0

func (i MessageCommandInteractionData) OptionsMember(k string) (Member, error)

OptionsMember returns the resolved Member (and User) for an Option

func (MessageCommandInteractionData) OptionsMessage added in v0.8.0

func (i MessageCommandInteractionData) OptionsMessage(k string) (Message, error)

OptionsMessage returns the resolved Message for an Option

func (MessageCommandInteractionData) OptionsRole added in v0.8.0

func (i MessageCommandInteractionData) OptionsRole(k string) (Role, error)

OptionsRole returns the resolved Role for an Option

func (MessageCommandInteractionData) OptionsUser added in v0.8.0

func (i MessageCommandInteractionData) OptionsUser(k string) (User, error)

OptionsUser returns the resolved User for an Option

type MessageReference

type MessageReference struct {
	MessageID Snowflake `json:"message_id"`
}

type MessageType

type MessageType int

MessageType https://discord.com/developers/docs/resources/channel#message-object-message-types

const (
	MESSAGE_TYPE_DEFAULT                                      MessageType = 0
	MESSAGE_TYPE_RECIPIENT_ADD                                MessageType = 1
	MESSAGE_TYPE_RECIPIENT_REMOVE                             MessageType = 2
	MESSAGE_TYPE_CALL                                         MessageType = 3
	MESSAGE_TYPE_CHANNEL_NAME_CHANGE                          MessageType = 4
	MESSAGE_TYPE_CHANNEL_ICON_CHANGE                          MessageType = 5
	MESSAGE_TYPE_CHANNEL_PINNED_MESSAGE                       MessageType = 6
	MESSAGE_TYPE_GUILD_MEMBER_JOIN                            MessageType = 7
	MESSAGE_TYPE_USER_PREMIUM_GUILD_SUBSCRIPTION              MessageType = 8
	MESSAGE_TYPE_USER_PREMIUM_GUILD_SUBSCRIPTION_TIER_1       MessageType = 9
	MESSAGE_TYPE_USER_PREMIUM_GUILD_SUBSCRIPTION_TIER_2       MessageType = 10
	MESSAGE_TYPE_USER_PREMIUM_GUILD_SUBSCRIPTION_TIER_3       MessageType = 11
	MESSAGE_TYPE_CHANNEL_FOLLOW_ADD                           MessageType = 12
	MESSAGE_TYPE_GUILD_DISCOVERY_DISQUALIFIED                 MessageType = 14
	MESSAGE_TYPE_GUILD_DISCOVERY_REQUALIFIED                  MessageType = 15
	MESSAGE_TYPE_GUILD_DISCOVERY_GRACE_PERIOD_INITIAL_WARNING MessageType = 16
	MESSAGE_TYPE_GUILD_DISCOVERY_GRACE_PERIOD_FINAL_WARNING   MessageType = 17
	MESSAGE_TYPE_THREAD_CREATED                               MessageType = 18
	MESSAGE_TYPE_REPLY                                        MessageType = 19
	MESSAGE_TYPE_CHAT_INPUT_COMMAND                           MessageType = 20
	MESSAGE_TYPE_THREAD_STARTER_MESSAGE                       MessageType = 21
	MESSAGE_TYPE_GUILD_INVITE_REMINDER                        MessageType = 22
	MESSAGE_TYPE_CONTEXT_MENU_COMMAND                         MessageType = 23
)

We could have used iota, but this scales better https://regex101.com/r/a3XWNs/1

type Modal struct {
	Title      string      `json:"title"`
	CustomID   string      `json:"custom_id"`
	Components []Component `json:"components"`
}

Modal represents a discord modal. when marshalled, it is wrapped in an action row. Thus, the components it should contain are the actual components you want displayed, rather than an action row wrapping them.

https://discord.com/developers/docs/interactions/message-components#text-inputs-text-input-styles

func (Modal) MarshalJSON added in v0.8.0

func (m Modal) MarshalJSON() ([]byte, error)

type ModalInteractionData added in v0.8.0

type ModalInteractionData struct {
	CustomID   string      `json:"custom_id,omitempty"`
	Components []Component `json:"components,omitempty"`
}

type Mux

type Mux struct {
	PublicKey  string // the hex public key provided by discord
	BasePath   string // base route path, default is "/"
	OnNotFound func(ResponseWriter, *Request[JsonRaw])
	Client     *http.Client
	AppID      Snowflake
	BotToken   string
	// contains filtered or unexported fields
}

Mux is a discord gateway muxer, which handles the routing

func NewMux

func NewMux(publicKey string, appID Snowflake, botToken string) *Mux

NewMux returns a new mux for routing slash commands

When you mount a command on the mux, it's prefix based routed, which means you can route to a button like `/list/next/456132153` having mounted `/list/next`

func (*Mux) Autocomplete

func (m *Mux) Autocomplete(route string, handler func(ResponseWriter, *Request[AutocompleteInteractionData]))

Autocomplete mounts an autocomplete route on the mux

func (*Mux) BulkRegisterCommand

func (m *Mux) BulkRegisterCommand(c []CreateCommander, options ...func(*CommandsOpt)) error

BulkRegisterCommand registers a slice of Command on discord

func (*Mux) ButtonComponent added in v0.8.0

func (m *Mux) ButtonComponent(route string, handler func(ResponseWriter, *Request[ButtonInteractionData]))

ButtonComponent mounts a button route on the mux

func (*Mux) CreateMessage added in v0.8.1

func (m *Mux) CreateMessage(channelID Snowflake, data Message) (*Message, error)

CreateMessage creates a new message in a channel

https://discord.com/developers/docs/resources/channel#create-message

func (*Mux) DeleteCommand

func (m *Mux) DeleteCommand(ID Snowflake, options ...func(*CommandsOpt)) error

DeleteCommand deletes a Command from discord

func (*Mux) DeleteFollowUpInteraction

func (m *Mux) DeleteFollowUpInteraction(token string, messageID Snowflake) error

DeleteFollowUpInteraction to delete a response to a FollowUpInteraction

https://discord.com/developers/docs/interactions/receiving-and-responding#delete-followup-message

func (*Mux) DeleteOriginalInteraction

func (m *Mux) DeleteOriginalInteraction(token string) error

DeleteOriginalInteraction to delete your initial response to an Interaction

https://discord.com/developers/docs/interactions/receiving-and-responding#edit-original-interaction-response

func (*Mux) EditFollowUpInteraction

func (m *Mux) EditFollowUpInteraction(token string, messageID Snowflake, data InteractionResponder) error

EditFollowUpInteraction to edit a response to a FollowUpInteraction

https://discord.com/developers/docs/interactions/receiving-and-responding#edit-followup-message

func (*Mux) EditOriginalInteraction

func (m *Mux) EditOriginalInteraction(token string, data InteractionResponder) error

EditOriginalInteraction to edit your initial response to an Interaction

https://discord.com/developers/docs/interactions/receiving-and-responding#edit-original-interaction-response

func (*Mux) FollowUpInteraction

func (m *Mux) FollowUpInteraction(token string, data InteractionResponder) error

FollowUpInteraction follows up a response to an Interaction

https://discord.com/developers/docs/interactions/receiving-and-responding#followup-messages

func (*Mux) GetCommands

func (m *Mux) GetCommands(options ...func(*CommandsOpt)) ([]Command, error)

GetCommands returns a slice of Command from the Mux

func (*Mux) GetFollowUpInteraction

func (m *Mux) GetFollowUpInteraction(token string, messageID Snowflake) (*InteractionRespData, error)

GetFollowUpInteraction returns the response to a FollowUpInteraction

https://discord.com/developers/docs/interactions/receiving-and-responding#get-followup-message

func (*Mux) GetOriginalInteraction

func (m *Mux) GetOriginalInteraction(token string) (*InteractionRespData, error)

GetOriginalInteraction returns the original response to an Interaction

https://discord.com/developers/docs/interactions/receiving-and-responding#get-original-interaction-response

func (*Mux) GetUser

func (m *Mux) GetUser(id Snowflake) (User, error)

GetUser returns a user by id

func (*Mux) ListenAndServe

func (m *Mux) ListenAndServe(addr string) error

ListenAndServe starts the gateway listening to events

func (*Mux) Lock

func (m *Mux) Lock()

Lock the mux, to be able to mount or unmount routes

func (*Mux) Me

func (m *Mux) Me() (User, error)

Me returns the current user

func (*Mux) MessageCommand added in v0.8.0

func (m *Mux) MessageCommand(route string, handler func(ResponseWriter, *Request[MessageCommandInteractionData]))

MessageCommand mounts a message command on the mux

func (*Mux) Modal added in v0.8.0

func (m *Mux) Modal(route string, handler func(ResponseWriter, *Request[ModalInteractionData]))

Modal mounts a modal interaction response on the mux

func (*Mux) Mount

func (m *Mux) Mount(typ InnerInteractionType, route string, handler any)

Mount is for mounting a Handler on the Mux

func (*Mux) RegisterCommand

func (m *Mux) RegisterCommand(c CreateCommander, options ...func(*CommandsOpt)) error

RegisterCommand registers a new Command on discord

func (*Mux) Route

func (m *Mux) Route(pattern string, fn func(m *Mux))

Route routes common parts along a pattern

func (*Mux) ServeHTTP

func (m *Mux) ServeHTTP(w http.ResponseWriter, r *http.Request)

ServeHTTP will serve HTTP requests with discord public key validation

func (*Mux) SlashCommand added in v0.8.0

func (m *Mux) SlashCommand(route string, handler func(ResponseWriter, *Request[SlashCommandInteractionData]))

SlashCommand mounts a slash command route on the mux

func (*Mux) Unlock

func (m *Mux) Unlock()

Unlock the mux, so it can route again

func (*Mux) UserCommand added in v0.8.0

func (m *Mux) UserCommand(route string, handler func(ResponseWriter, *Request[UserCommandInteractionData]))

UserCommand mounts a user command on the mux

type NumberOption

type NumberOption struct {
	Name         string
	Description  string
	Required     bool
	Choices      []Choice[any]
	ChannelTypes []ChannelType
	Autocomplete bool
}

NumberOption represents a float64 option

func NewNumberOption

func NewNumberOption(name string, description string, required bool, choices ...Choice[float64]) *NumberOption

NewNumberOption returns a new NumberOption

func (*NumberOption) CanAutocomplete

func (o *NumberOption) CanAutocomplete() *NumberOption

CanAutocomplete sets the option as autocomplete-able

func (*NumberOption) ChanTypes

func (o *NumberOption) ChanTypes(typs ...ChannelType) *NumberOption

ChanTypes sets the options channel types

func (*NumberOption) MarshalJSON

func (o *NumberOption) MarshalJSON() ([]byte, error)

MarshalJSON returns the JSON representation of the option

type Option

type Option struct {
	Name        string        `json:"name"`
	Type        OptionType    `json:"type"`
	Value       JsonRaw       `json:"value"`
	Description string        `json:"description,omitempty"`
	Required    bool          `json:"required,omitempty"`
	Options     []Option      `json:"options,omitempty"`
	Choices     []Choice[any] `json:"choices,omitempty"`
	Focused     bool          `json:"focused,omitempty"`
}

Option is an option for an application Command

type OptionType

type OptionType int
const (
	OPTION_SUB_COMMAND OptionType = iota + 1
	OPTION_SUB_COMMAND_GROUP
	OPTION_STRING
	OPTION_INTEGER
	OPTION_BOOLEAN
	OPTION_USER
	OPTION_CHANNEL
	OPTION_ROLE
	OPTION_MENTIONABLE
	OPTION_NUMBER
)

type OptionsInteractions

type OptionsInteractions map[string]JsonRaw

OptionsInteractions is the options for an Interaction

func (OptionsInteractions) Any

func (o OptionsInteractions) Any(k string) (any, error)

Any returns the Option with key k of type any

func (OptionsInteractions) Bool

func (o OptionsInteractions) Bool(k string) (bool, error)

Bool returns the Option with key k of type bool

func (OptionsInteractions) Float32

func (o OptionsInteractions) Float32(k string) (float32, error)

Float32 returns the Option with key k of type float32

func (OptionsInteractions) Float64

func (o OptionsInteractions) Float64(k string) (float64, error)

Float64 returns the Option with key k of type float64

func (OptionsInteractions) Int

func (o OptionsInteractions) Int(k string) (int, error)

Int returns the Option with key k of type int

func (OptionsInteractions) Int32

func (o OptionsInteractions) Int32(k string) (int32, error)

Int32 returns the Option with key k of type int32

func (OptionsInteractions) Int64

func (o OptionsInteractions) Int64(k string) (int64, error)

Int64 returns the Option with key k of type int64

func (OptionsInteractions) MarshalJSON

func (o OptionsInteractions) MarshalJSON() ([]byte, error)

MarshalJSON implements json.Marshaler

func (OptionsInteractions) Snowflake

func (o OptionsInteractions) Snowflake(k string) (Snowflake, error)

Snowflake returns the Option with key k of type Snowflake

func (OptionsInteractions) String

func (o OptionsInteractions) String(k string) (string, error)

String returns the Option with key k of type string

func (OptionsInteractions) Uint

func (o OptionsInteractions) Uint(k string) (uint, error)

Uint returns the Option with key k of type uint

func (OptionsInteractions) Uint32

func (o OptionsInteractions) Uint32(k string) (uint32, error)

Uint32 returns the Option with key k of type uint32

func (OptionsInteractions) Uint64

func (o OptionsInteractions) Uint64(k string) (uint64, error)

Uint64 returns the Option with key k of type uint64

func (*OptionsInteractions) UnmarshalJSON

func (o *OptionsInteractions) UnmarshalJSON(b []byte) error

UnmarshalJSON implements json.Unmarshaler

type Overwrite

type Overwrite struct {
	ID Snowflake `json:"id"`
	// Type: 0 = @role, 1 = @user
	Type int `json:"type"`
	// Permission bit set
	Allow string `json:"allow"`
	// Permission bit set
	Deny string `json:"deny"`
}

Overwrite https://discord.com/developers/docs/resources/channel#overwrite-object

type PartialCommandInteraction added in v0.8.0

type PartialCommandInteraction struct {
	Type int `json:"type"`
	JsonRaw
}

type PartialRoutingType added in v0.8.0

type PartialRoutingType struct {
	ID            Snowflake `json:"id"`
	Type          int       `json:"type"`
	ComponentType int       `json:"component_type"`
	Name          string    `json:"name"`
	CustomID      string    `json:"custom_id"`
	// contains filtered or unexported fields
}

func (PartialRoutingType) OptionsMember added in v0.8.0

func (i PartialRoutingType) OptionsMember(k string) (Member, error)

OptionsMember returns the resolved Member (and User) for an Option

func (PartialRoutingType) OptionsMessage added in v0.8.0

func (i PartialRoutingType) OptionsMessage(k string) (Message, error)

OptionsMessage returns the resolved Message for an Option

func (PartialRoutingType) OptionsRole added in v0.8.0

func (i PartialRoutingType) OptionsRole(k string) (Role, error)

OptionsRole returns the resolved Role for an Option

func (PartialRoutingType) OptionsUser added in v0.8.0

func (i PartialRoutingType) OptionsUser(k string) (User, error)

OptionsUser returns the resolved User for an Option

type Provider

type Provider struct {
	Name string `json:"name,omitempty"`
	URL  string `json:"url,omitempty"`
}

Provider is an embed provider

type Reaction

type Reaction struct {
	Count int   `json:"count"`
	Me    bool  `json:"me"`
	Emoji Emoji `json:"emoji"`
}

Reaction https://discord.com/developers/docs/resources/channel#reaction-object

type Request added in v0.8.0

type Request[T InteractionDataConstraint] struct {
	Interaction[T]
	Context context.Context
}

Request is an incoming request Interaction

type Resolved

type Resolved struct {
	Users    ResolvedData[User]    `json:"users,omitempty"`
	Members  ResolvedData[Member]  `json:"members,omitempty"`
	Roles    ResolvedData[Role]    `json:"roles,omitempty"`
	Messages ResolvedData[Message] `json:"messages,omitempty"`
}

type ResolvedData

type ResolvedData[T ResolvedDataConstraint] map[Snowflake]T

ResolvedData is a generic mapping of Snowflakes to resolved data structs

func (ResolvedData[T]) First

func (r ResolvedData[T]) First() T

First returns the first resolved data ResolvedData is a map (which is unordered), so First should only be used when ResolvedData has a single element.

type ResolvedDataConstraint

type ResolvedDataConstraint interface {
	User | Member | Role | Message
}

type RespB

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

RespB is an InteractionRespData builder

func NewResp

func NewResp() *RespB

NewResp Returns a new response builder

func (*RespB) ActionRow

func (b *RespB) ActionRow(c ...Component) *RespB

ActionRow adds an action row to the InteractionRespData

func (*RespB) AllowedMentions

func (r *RespB) AllowedMentions(a *AllowedMentions) *RespB

AllowedMentions adds the allowed mentions to the InteractionRespData

func (*RespB) Attachment

func (b *RespB) Attachment(body io.Reader, filename string) *RespB

Attachement adds an attachment to the InteractionRespData

func (*RespB) Attachments

func (b *RespB) Attachments(a ...Attachment) *RespB

Attachments adds attachments to the InteractionRespData

func (*RespB) Choice

func (b *RespB) Choice(name string, value any) *RespB

Choice adds a choice to the InteractionRespData

func (*RespB) Choices

func (b *RespB) Choices(c ...Choice[any]) *RespB

Choices adds choices to the InteractionRespData

func (*RespB) Components

func (b *RespB) Components(c ...Component) *RespB

Components adds components to the InteractionRespData

func (*RespB) Content

func (r *RespB) Content(s string) *RespB

Content adds the content to the InteractionRespData

func (*RespB) Contentf

func (r *RespB) Contentf(s string, args ...any) *RespB

Contentf adds the content to the InteractionRespData

func (*RespB) Embeds

func (r *RespB) Embeds(e ...Embedder) *RespB

Embeds adds embeds to the InteractionRespData

func (*RespB) Ephemeral

func (r *RespB) Ephemeral() *RespB

Ephemeral adds the ephemeral flag to the InteractionRespData

func (*RespB) Flags

func (r *RespB) Flags(i IntResponseFlags) *RespB

Flags adds the flags to the InteractionRespData

func (*RespB) InteractionRespData

func (r *RespB) InteractionRespData() *InteractionRespData

InteractionRespData implements InteractionResponder

func (*RespB) TTS

func (r *RespB) TTS(tts bool) *RespB

TTS adds the tts to the InteractionRespData

type Responder

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

Responder loosely maps to the discord gateway response https://discord.com/developers/docs/interactions/receiving-and-responding#responding-to-an-interaction

func (*Responder) Ack added in v0.8.0

func (r *Responder) Ack()

Pong responds to pings on the gateway

func (*Responder) Autocomplete

func (r *Responder) Autocomplete(i InteractionResponder)

Autocomplete responds to the interaction with autocomplete data

func (*Responder) DeferedRespond

func (r *Responder) DeferedRespond()

DeferedRespond responds in defered

func (*Responder) DeferedUpdate

func (r *Responder) DeferedUpdate()

DeferedUpdate updates the target message in defered

func (*Responder) Modal added in v0.8.0

func (r *Responder) Modal(m Modal)

Modal responds to the interaction with modal data

func (*Responder) Respond

func (r *Responder) Respond(i InteractionResponder)

Respond responds to the interaction directly

func (*Responder) Update

func (r *Responder) Update(i InteractionResponder)

Update updates the target message

type ResponseWriter

type ResponseWriter interface {
	Ack()
	Respond(InteractionResponder)
	DeferedRespond()
	Update(InteractionResponder)
	DeferedUpdate()
	Autocomplete(InteractionResponder)
	Modal(Modal)
}

ResponseWriter handles responding to interactions https://discord.com/developers/docs/interactions/receiving-and-responding#interaction-response-object-interaction-callback-type

type Role

type Role struct {
	ID          Snowflake `json:"id"`
	Name        string    `json:"name"`
	Permissions uint64    `json:"permissions,string"`
	Position    int       `json:"position"`
	Color       uint32    `json:"color"`
	Hoist       bool      `json:"hoist"`
	Managed     bool      `json:"managed"`
	Mentionable bool      `json:"mentionable"`
}

Role is a user's role https://discord.com/developers/docs/topics/permissions#role-object

type RoleOption

type RoleOption struct {
	Name         string
	Description  string
	Required     bool
	Choices      []Choice[any]
	ChannelTypes []ChannelType
	Autocomplete bool
}

RoleOption represents a Snowflake option

func NewRoleOption

func NewRoleOption(name string, description string, required bool, choices ...Choice[Snowflake]) *RoleOption

NewRoleOption returns a new RoleOption

func (*RoleOption) ChanTypes

func (o *RoleOption) ChanTypes(typs ...ChannelType) *RoleOption

ChanTypes sets the options channel types

func (*RoleOption) MarshalJSON

func (o *RoleOption) MarshalJSON() ([]byte, error)

MarshalJSON returns the JSON representation of the option

type SelectInteractionData added in v0.8.0

type SelectInteractionData struct {
	CustomID      string        `json:"custom_id,omitempty"`
	ComponentType ComponentType `json:"component_type"`
	Values        []any         `json:"values,omitempty"`
}

type SelectOption

type SelectOption struct {
	Label       string `json:"label"`
	Value       string `json:"value"`
	Description string `json:"description,omitempty"`
	Emoji       *Emoji `json:"emoji,omitempty"`
	Default     bool   `json:"default,omitempty"`
}

SelectOption https://discord.com/developers/docs/interactions/message-components#select-menu-object-select-option-structure

type SlashCommandInteractionData added in v0.8.0

type SlashCommandInteractionData struct {
	ID   Snowflake `json:"id"`
	Name string    `json:"name"`
	Type int       `json:"type"`
	// contains filtered or unexported fields
}

func (SlashCommandInteractionData) OptionsMember added in v0.8.0

func (i SlashCommandInteractionData) OptionsMember(k string) (Member, error)

OptionsMember returns the resolved Member (and User) for an Option

func (SlashCommandInteractionData) OptionsMessage added in v0.8.0

func (i SlashCommandInteractionData) OptionsMessage(k string) (Message, error)

OptionsMessage returns the resolved Message for an Option

func (SlashCommandInteractionData) OptionsRole added in v0.8.0

func (i SlashCommandInteractionData) OptionsRole(k string) (Role, error)

OptionsRole returns the resolved Role for an Option

func (SlashCommandInteractionData) OptionsUser added in v0.8.0

func (i SlashCommandInteractionData) OptionsUser(k string) (User, error)

OptionsUser returns the resolved User for an Option

type Snowflake

type Snowflake uint64

Snowflake is a DiscordSnowflake ID

func SnowflakeFromString

func SnowflakeFromString(s string) Snowflake

corde.SnowflakeFromString returns aSnowflake from a string

func (Snowflake) MarshalJSON

func (s Snowflake) MarshalJSON() ([]byte, error)

MarshalJSON implements json.Marshaler

func (Snowflake) String

func (s Snowflake) String() string

String implements fmt.Stringer

func (*Snowflake) UnmarshalJSON

func (s *Snowflake) UnmarshalJSON(b []byte) error

UnmarshalJSON implements json.Unmarshaler

type Sticker

type Sticker struct {
	ID          Snowflake     `json:"id"`
	Name        string        `json:"name"`
	Tags        string        `json:"tags"`
	Asset       string        `json:"asset"`
	Type        int           `json:"type"`
	FormatType  StickerFormat `json:"format_type"`
	Description string        `json:"description,omitempty"`
	PackID      Snowflake     `json:"pack_id,omitempty"`
	Available   bool          `json:"available,omitempty"`
	GuildID     Snowflake     `json:"guild_id,omitempty"`
	User        User          `json:"user,omitempty"`
	SortValue   int           `json:"sort_value,omitempty"`
}

Sticker https://discord.com/developers/docs/resources/sticker#sticker-object

type StickerFormat

type StickerFormat int

https://discord.com/developers/docs/resources/sticker#sticker-object-sticker-format-types

const (
	STICKER_FORMAT_PNG StickerFormat = iota + 1
	STICKER_FORMAT_APNG
	STICKER_FORMAT_LOTTIE
)

type StickerItem

type StickerItem struct {
	ID         Snowflake     `json:"id"`
	Name       string        `json:"name"`
	FormatType StickerFormat `json:"format_type"`
}

StickerItem

type StringOption

type StringOption struct {
	Name         string
	Description  string
	Required     bool
	Choices      []Choice[any]
	ChannelTypes []ChannelType
	Autocomplete bool
}

StringOption represents a string option

func NewStringOption

func NewStringOption(name string, description string, required bool, choices ...Choice[string]) *StringOption

NewStringOption returns a new StringOption

func (*StringOption) CanAutocomplete

func (o *StringOption) CanAutocomplete() *StringOption

CanAutocomplete sets the option as autocomplete-able

func (*StringOption) ChanTypes

func (o *StringOption) ChanTypes(typs ...ChannelType) *StringOption

ChanTypes sets the options channel types

func (*StringOption) MarshalJSON

func (o *StringOption) MarshalJSON() ([]byte, error)

MarshalJSON returns the JSON representation of the option

type Style added in v0.8.0

type Style int

Style is the style of a button Component

const (
	BUTTON_PRIMARY   Style = iota + 1 // BUTTON_PRIMARY blurple
	BUTTON_SECONDARY                  // BUTTON_SECONDARY grey
	BUTTON_SUCCESS                    // BUTTON_SUCCESS green
	BUTTON_DANGER                     // BUTTON_DANGER red
	BUTTON_LINK                       // BUTTON_LINK grey, navigate to URL

	TEXT_SHORT     = 1
	TEXT_PARAGRAPH = 2
)

type SubcommandGroupOption

type SubcommandGroupOption struct {
	Name        string
	Description string
	Options     []CreateOptioner
}

SubcommandGroupOption is an option that is a subcommand group

func NewSubcommandGroup

func NewSubcommandGroup(name string, description string, options ...CreateOptioner) *SubcommandGroupOption

NewSubcommandGroup returns a new subcommand group

func (*SubcommandGroupOption) MarshalJSON

func (o *SubcommandGroupOption) MarshalJSON() ([]byte, error)

type SubcommandOption

type SubcommandOption struct {
	Name        string
	Description string
	Options     []CreateOptioner
}

SubcommandOption is an option that is a subcommand

func NewSubcommand

func NewSubcommand(name string, description string, options ...CreateOptioner) *SubcommandOption

NewSubcommand returns a new subcommand

func (*SubcommandOption) MarshalJSON

func (o *SubcommandOption) MarshalJSON() ([]byte, error)

type Team

type Team struct {
	Icon        string       `json:"icon,omitempty"`
	ID          Snowflake    `json:"id"`
	Members     []TeamMember `json:"members"`
	Name        string       `json:"name"`
	OwnerUserID Snowflake    `json:"owner_user_id"`
}

Team https://discord.com/developers/docs/topics/teams#data-models-team-object

type TeamMember

type TeamMember struct {
	MembershipState int `json:"membership_state"`
	// 	will always be ["*"]
	Permissions []string  `json:"permissions"`
	TeamID      Snowflake `json:"team_id"`
	User        User      `json:"user"`
}

TeamMember https://discord.com/developers/docs/topics/teams#data-models-team-member-object

type TextInputComponent added in v0.8.0

type TextInputComponent struct {
	CustomID    string `json:"custom_id"`
	Style       Style  `json:"style"`
	Label       string `json:"label"`
	MinLength   int    `json:"min_length,omitempty"`
	MaxLength   int    `json:"max_length,omitempty"`
	Required    bool   `json:"required,omitempty"`
	Value       string `json:"value,omitempty"`
	Placeholder string `json:"place_holder,omitempty"`
}

TextInputComponent

https://discord.com/developers/docs/interactions/message-components#text-inputs-text-input-structure

func (TextInputComponent) Component added in v0.8.0

func (t TextInputComponent) Component() Component

type TextInputInteractionData added in v0.8.0

type TextInputInteractionData struct {
	CustomID    string      `json:"custom_id"`
	Title       string      `json:"title"`
	Style       int         `json:"style"`
	Label       string      `json:"label"`
	MinLenght   int         `json:"min_length,omitempty"`
	MaxLenght   int         `json:"max_length,omitempty"`
	Required    bool        `json:"required,omitempty"`
	Value       string      `json:"value,omitempty"`
	Placeholder string      `json:"placeholder,omitempty"`
	Components  []Component `json:"components"`
}

type Thumbnail

type Thumbnail struct {
	URL string `json:"url"`
}

type Timestamp

type Timestamp time.Time

Timestamp is a discord timestamp It is represented as a string in the ISO 8601 format

func (Timestamp) MarshalJSON

func (t Timestamp) MarshalJSON() ([]byte, error)

func (Timestamp) String

func (t Timestamp) String() string

func (*Timestamp) UnmarshalJSON

func (t *Timestamp) UnmarshalJSON(b []byte) error

type User

type User struct {
	ID            Snowflake `json:"id"`
	Username      string    `json:"username"`
	Discriminator string    `json:"discriminator"`
	Avatar        Hash      `json:"avatar,omitempty"`
	Bot           bool      `json:"bot,omitempty"`
	System        bool      `json:"system,omitempty"`
	MFAEnabled    bool      `json:"mfa_enabled,omitempty"`
	Verified      bool      `json:"verified,omitempty"`
	Email         string    `json:"email,omitempty"`
	Flags         int       `json:"flags,omitempty"`
	Locale        string    `json:"locale,omitempty"`
	Banner        string    `json:"banner,omitempty"`
	AccentColor   uint32    `json:"accent_color,omitempty"`
	PremiumType   int       `json:"premium_type,omitempty"`
	PublicFlags   int       `json:"public_flags,omitempty"`
}

User is a Discord User

func (User) AvatarPNG

func (u User) AvatarPNG() string

AvatarPNG returns a png url of this hash

func (User) AvatarURL

func (u User) AvatarURL() string

AvatarURL returns a url of this user, being animated if it can

type UserCommandInteractionData added in v0.8.0

type UserCommandInteractionData struct {
	ID       Snowflake `json:"id"`
	TargetID Snowflake `json:"target_id,omitempty"`
	Name     string    `json:"name"`
	Type     int       `json:"type"`
	// contains filtered or unexported fields
}

func (UserCommandInteractionData) OptionsMember added in v0.8.0

func (i UserCommandInteractionData) OptionsMember(k string) (Member, error)

OptionsMember returns the resolved Member (and User) for an Option

func (UserCommandInteractionData) OptionsMessage added in v0.8.0

func (i UserCommandInteractionData) OptionsMessage(k string) (Message, error)

OptionsMessage returns the resolved Message for an Option

func (UserCommandInteractionData) OptionsRole added in v0.8.0

func (i UserCommandInteractionData) OptionsRole(k string) (Role, error)

OptionsRole returns the resolved Role for an Option

func (UserCommandInteractionData) OptionsUser added in v0.8.0

func (i UserCommandInteractionData) OptionsUser(k string) (User, error)

OptionsUser returns the resolved User for an Option

type UserOption

type UserOption struct {
	Name         string
	Description  string
	Required     bool
	Choices      []Choice[any]
	ChannelTypes []ChannelType
	Autocomplete bool
}

UserOption represents a Snowflake option

func NewUserOption

func NewUserOption(name string, description string, required bool, choices ...Choice[Snowflake]) *UserOption

NewUserOption returns a new UserOption

func (*UserOption) ChanTypes

func (o *UserOption) ChanTypes(typs ...ChannelType) *UserOption

ChanTypes sets the options channel types

func (*UserOption) MarshalJSON

func (o *UserOption) MarshalJSON() ([]byte, error)

MarshalJSON returns the JSON representation of the option

type Video

type Video struct {
	URL      string `json:"url,omitempty"`
	ProxyURL string `json:"proxy_url,omitempty"`
	Height   int    `json:"height,omitempty"`
	Width    int    `json:"width,omitempty"`
}

Video is an embed video

Directories

Path Synopsis
0_example
nft
Package format https://discord.com/developers/docs/reference#message-formatting
Package format https://discord.com/developers/docs/reference#message-formatting
internal

Jump to

Keyboard shortcuts

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