Documentation
¶
Index ¶
- Constants
- type ActionsRow
- type Bucket
- type Button
- type ButtonStyle
- type Channel
- type Client
- func (client *Client) AddHandler(event gateway.EventType, function any) error
- func (client *Client) ChooseSelectMenu(message gateway.EventMessage, row int, column int, values []string) error
- func (client *Client) ClickButton(message gateway.EventMessage, row int, column int) error
- func (client *Client) ClickDmButton(message gateway.EventMessage, row int, column int) error
- func (client *Client) Close()
- func (client *Client) Connect() error
- func (client *Client) GetAuthorizationCode() (string, error)
- func (client *Client) GetCommandInfo(commandName string) *CommandData
- func (client *Client) GetCommands(guildID string) (map[string]CommandData, error)
- func (client *Client) GetGuildID(channelID string) (string, error)
- func (client *Client) RequestWithLockedBucket(method, urlStr string, b []byte, bucket *Bucket, sequence int) ([]byte, error)
- func (client *Client) SafeGetUsername() string
- func (client *Client) SendChatMessage(content string) error
- func (client *Client) SendCommand(commandName string, options map[string]string) error
- func (client *Client) SendMessage(op gateway.Opcode, data gateway.MessageData) error
- func (client *Client) SendSubCommand(commandName string, subCommandName string, options map[string]string) error
- func (client *Client) SubmitModal(modal gateway.EventModalCreate) error
- type CommandData
- type CommandOptions
- type CommandSendOptions
- type ComponentEmoji
- type ComponentType
- type Handlers
- type MessageComponent
- type RateLimiter
- type SelectMenu
- type SelectMenuDefaultValue
- type SelectMenuDefaultValueType
- type SelectMenuOption
- type SelectMenuType
- type TextInput
- type TextInputStyle
- type TooManyRequests
Constants ¶
const ( StringSelectMenu = SelectMenuType(SelectMenuComponent) UserSelectMenu = SelectMenuType(UserSelectMenuComponent) RoleSelectMenu = SelectMenuType(RoleSelectMenuComponent) MentionableSelectMenu = SelectMenuType(MentionableSelectMenuComponent) ChannelSelectMenu = SelectMenuType(ChannelSelectMenuComponent) )
SelectMenu types.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type ActionsRow ¶
type ActionsRow struct {
Components []MessageComponent `json:"components"`
}
ActionsRow is a container for components within one row.
func (ActionsRow) MarshalJSON ¶
func (r ActionsRow) MarshalJSON() ([]byte, error)
MarshalJSON is a method for marshaling ActionsRow to a JSON object.
func (ActionsRow) Type ¶
func (r ActionsRow) Type() ComponentType
Type is a method to get the type of a component.
func (*ActionsRow) UnmarshalJSON ¶
func (r *ActionsRow) UnmarshalJSON(data []byte) error
UnmarshalJSON is a helper function to unmarshal Actions Row.
type Bucket ¶
type Bucket struct {
sync.Mutex
Key string
Remaining int
Userdata interface{}
// contains filtered or unexported fields
}
Bucket represents a ratelimit bucket, each bucket gets ratelimited individually (-global ratelimits)
type Button ¶
type Button struct {
Label string `json:"label"`
Style ButtonStyle `json:"style"`
Disabled bool `json:"disabled"`
Emoji ComponentEmoji `json:"emoji"`
// NOTE: Only button with LinkButton style can have link. Also, URL is mutually exclusive with CustomID.
URL string `json:"url,omitempty"`
CustomID string `json:"custom_id,omitempty"`
}
Button represents button component.
func (Button) MarshalJSON ¶
MarshalJSON is a method for marshaling Button to a JSON object.
func (Button) Type ¶
func (Button) Type() ComponentType
Type is a method to get the type of a component.
type ButtonStyle ¶
type ButtonStyle uint
ButtonStyle is style of button.
const ( // PrimaryButton is a button with blurple color. PrimaryButton ButtonStyle = 1 // SecondaryButton is a button with grey color. SecondaryButton ButtonStyle = 2 // SuccessButton is a button with green color. SuccessButton ButtonStyle = 3 // DangerButton is a button with red color. DangerButton ButtonStyle = 4 // LinkButton is a special type of button which navigates to a URL. Has grey color. LinkButton ButtonStyle = 5 )
Button styles.
type Client ¶
type Client struct {
Ctx context.Context
Token string
Handlers Handlers
Gateway gateway.Gateway
ChannelID string
GuildID string
CommandsData *[]CommandData
RateLimiter *RateLimiter
}
func (*Client) AddHandler ¶
func (*Client) ChooseSelectMenu ¶
func (*Client) ClickButton ¶
func (*Client) ClickDmButton ¶
func (*Client) GetAuthorizationCode ¶
func (*Client) GetCommandInfo ¶
func (client *Client) GetCommandInfo(commandName string) *CommandData
func (*Client) GetCommands ¶
func (client *Client) GetCommands(guildID string) (map[string]CommandData, error)
func (*Client) RequestWithLockedBucket ¶
func (*Client) SafeGetUsername ¶
func (*Client) SendChatMessage ¶
func (*Client) SendCommand ¶
func (*Client) SendMessage ¶
func (*Client) SendSubCommand ¶
func (*Client) SubmitModal ¶
func (client *Client) SubmitModal(modal gateway.EventModalCreate) error
type CommandData ¶
type CommandData struct {
ID string `json:"id"`
Type int `json:"type"`
ApplicationID string `json:"application_id"`
Version string `json:"version"`
Name string `json:"name"`
Description string `json:"description"`
DmPermission bool `json:"dm_permission"`
IntegrationTypes []int `json:"integration_types"`
GlobalPopularityRank int `json:"global_popularity_rank"`
Options CommandOptions `json:"options,omitempty"`
}
type CommandOptions ¶
type CommandSendOptions ¶
type ComponentEmoji ¶
type ComponentEmoji struct {
Name string `json:"name,omitempty"`
ID string `json:"id,omitempty"`
Animated bool `json:"animated,omitempty"`
}
ComponentEmoji represents button emoji, if it does have one.
type ComponentType ¶
type ComponentType uint
ComponentType is type of component.
const ( ActionsRowComponent ComponentType = 1 ButtonComponent ComponentType = 2 SelectMenuComponent ComponentType = 3 TextInputComponent ComponentType = 4 UserSelectMenuComponent ComponentType = 5 RoleSelectMenuComponent ComponentType = 6 MentionableSelectMenuComponent ComponentType = 7 ChannelSelectMenuComponent ComponentType = 8 )
MessageComponent types.
type Handlers ¶
type Handlers struct {
OnReady []func(data gateway.EventReady)
OnMessageCreate []func(data gateway.EventMessage)
OnMessageUpdate []func(data gateway.EventMessage)
OnModalCreate []func(data gateway.EventModalCreate)
// contains filtered or unexported fields
}
type MessageComponent ¶
type MessageComponent interface {
json.Marshaler
Type() ComponentType
}
MessageComponent is a base interface for all message components.
func MessageComponentFromJSON ¶
func MessageComponentFromJSON(b []byte) (MessageComponent, error)
MessageComponentFromJSON is a helper function for unmarshaling message components
type RateLimiter ¶
RateLimiter holds all ratelimit buckets
func (*RateLimiter) GetBucket ¶
func (r *RateLimiter) GetBucket(key string) *Bucket
GetBucket retrieves or creates a bucket
func (*RateLimiter) GetWaitTime ¶
func (r *RateLimiter) GetWaitTime(b *Bucket, minRemaining int) time.Duration
GetWaitTime returns the duration you should wait for a Bucket
func (*RateLimiter) LockBucket ¶
func (r *RateLimiter) LockBucket(bucketID string) *Bucket
LockBucket Locks until a request can be made
func (*RateLimiter) LockBucketObject ¶
func (r *RateLimiter) LockBucketObject(b *Bucket) *Bucket
LockBucketObject Locks an already resolved bucket until a request can be made
type SelectMenu ¶
type SelectMenu struct {
// Type of the select menu.
MenuType SelectMenuType `json:"type,omitempty"`
// CustomID is a developer-defined identifier for the select menu.
CustomID string `json:"custom_id,omitempty"`
// The text which will be shown in the menu if there's no default options or all options was deselected and component was closed.
Placeholder string `json:"placeholder"`
// This value determines the minimal amount of selected items in the menu.
MinValues *int `json:"min_values,omitempty"`
// This value determines the maximal amount of selected items in the menu.
// If MaxValues or MinValues are greater than one then the user can select multiple items in the component.
MaxValues int `json:"max_values,omitempty"`
// List of default values for auto-populated select menus.
// NOTE: Number of entries should be in the range defined by MinValues and MaxValues.
DefaultValues []SelectMenuDefaultValue `json:"default_values,omitempty"`
Options []SelectMenuOption `json:"options,omitempty"`
Disabled bool `json:"disabled"`
}
SelectMenu represents select menu component.
func (SelectMenu) MarshalJSON ¶
func (s SelectMenu) MarshalJSON() ([]byte, error)
MarshalJSON is a method for marshaling SelectMenu to a JSON object.
func (SelectMenu) Type ¶
func (s SelectMenu) Type() ComponentType
Type is a method to get the type of a component.
type SelectMenuDefaultValue ¶
type SelectMenuDefaultValue struct {
// ID of the entity.
ID string `json:"id"`
// Type of the entity.
Type SelectMenuDefaultValueType `json:"type"`
}
SelectMenuDefaultValue represents an entity selected by default in auto-populated select menus.
type SelectMenuDefaultValueType ¶
type SelectMenuDefaultValueType string
SelectMenuDefaultValueType represents the type of an entity selected by default in auto-populated select menus.
const ( SelectMenuDefaultValueUser SelectMenuDefaultValueType = "user" SelectMenuDefaultValueRole SelectMenuDefaultValueType = "role" SelectMenuDefaultValueChannel SelectMenuDefaultValueType = "channel" )
SelectMenuDefaultValue types.
type SelectMenuOption ¶
type SelectMenuOption struct {
Label string `json:"label,omitempty"`
Value string `json:"value"`
Description string `json:"description"`
Emoji ComponentEmoji `json:"emoji"`
// Determines whenever option is selected by default or not.
Default bool `json:"default"`
}
SelectMenuOption represents an option for a select menu.
type TextInput ¶
type TextInput struct {
CustomID string `json:"custom_id"`
Label string `json:"label"`
Style TextInputStyle `json:"style"`
Placeholder string `json:"placeholder,omitempty"`
Value string `json:"value,omitempty"`
Required bool `json:"required"`
MinLength int `json:"min_length,omitempty"`
MaxLength int `json:"max_length,omitempty"`
}
TextInput represents text input component.
func (TextInput) MarshalJSON ¶
MarshalJSON is a method for marshaling TextInput to a JSON object.
func (TextInput) Type ¶
func (TextInput) Type() ComponentType
Type is a method to get the type of a component.
type TextInputStyle ¶
type TextInputStyle uint
TextInputStyle is style of text in TextInput component.
const ( TextInputShort TextInputStyle = 1 TextInputParagraph TextInputStyle = 2 )
Text styles
type TooManyRequests ¶
type TooManyRequests struct {
Bucket string `json:"bucket"`
Message string `json:"message"`
RetryAfter float64 `json:"retry_after"`
}
A TooManyRequests struct holds information received from Discord when receiving a HTTP 429 response.