disgo

package module
v1.5.1 Latest Latest
Warning

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

Go to latest
Published: Aug 10, 2022 License: MIT Imports: 15 Imported by: 0

README

disgo

Quick Example

package main

import (
	"fmt"
	"github.com/jnsougata/disgo"
	"os"
)

func main() {
	bot := disgo.Bot(disgo.Intents(), true, disgo.Presence{
		Since:  0,
		Status: "dnd",
		Activity: disgo.Activity{
			Name: "/ping",
			Type: 2,
		},
	})
	bot.OnReady(onReady)
	bot.Run(os.Getenv("DISCORD_TOKEN"))
}

func onReady(b disgo.BotUser) {
	fmt.Println(fmt.Sprintf("Running %s#%s (ID: %s)", b.Username, b.Discriminator, b.Id))
	fmt.Println("-------")
}

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Bot

func Bot(intent Intent, cache bool, presence Presence) *connection

Bot is a function that represents a connection to discord.

func Permissions added in v1.5.1

func Permissions() *permissions

Types

type ActionRow

type ActionRow struct {
	Buttons    []Button // max 5 buttons
	SelectMenu SelectMenu
}

type Activity

type Activity struct {
	Name string `json:"name"` // "name" of the activity
	Type int    `json:"type"` // (0: playing), (1: streaming), (2: listening), (3: watching), (5: competing)
	URL  string `json:"url"`  // "url" of type (3: streaming) activity only
}

func (*Activity) Marshal

func (a *Activity) Marshal() map[string]interface{}

type ApplicationCommand

type ApplicationCommand struct {
	Type              CommandType // defaults to chat input
	Name              string      // must be less than 32 characters
	Description       string      // must be less than 100 characters
	Options           []Option
	DMPermission      bool // default: false
	MemberPermissions int  // default: send_messages
	GuildId           int64

	Task             func(bot BotUser, ctx Context, options map[string]Option)
	AutocompleteTask func(bot BotUser, ctx Context, choices ...Choice)
	// contains filtered or unexported fields
}

ApplicationCommand is a base type for all discord application commands

func (*ApplicationCommand) SubCommands added in v1.5.1

func (cmd *ApplicationCommand) SubCommands(subcommands ...SubCommand)

func (*ApplicationCommand) SubcommandGroups added in v1.5.1

func (cmd *ApplicationCommand) SubcommandGroups(subcommandGroups ...SubcommandGroup)

type Asset added in v1.5.1

type Asset struct {
	Hash   string
	Size   int64
	Format string
	Extras string
}

func (Asset) CustomURL added in v1.5.1

func (a Asset) CustomURL(size int64, format string) string

func (Asset) URL added in v1.5.1

func (a Asset) URL() string

type Attachment

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

Attachment represents a base Discord attachment

type BotUser

type BotUser struct {
	Id            string `json:"id"`
	Username      string `json:"username"`
	Discriminator string `json:"discriminator"`
	Avatar        string `json:"avatar"`
	MfaEnabled    bool   `json:"mfa_enabled"`
	Banner        string `json:"banner"`
	Color         int    `json:"accent_color"`
	Locale        string `json:"locale"`
	Verified      bool   `json:"verified"`
	Flags         int    `json:"flags"`
	PublicFlags   int    `json:"public_flags"`
	Latency       int64  `json:"latency"`
	IsReady       bool
	Guilds        map[string]*Guild
	Users         map[string]*User
}

type Button

type Button struct {
	Style    int    // default: 1 (blue) More: 2 (grey), 3 (green), 4 (red), 5 (link)
	Label    string // default: "Button"
	Emoji    PartialEmoji
	URL      string // only for style 5 (link)
	Disabled bool

	OnClick func(bot BotUser, comp Context)
	// contains filtered or unexported fields
}

type Channel

type Channel struct {
	Id                         string        `json:"id"`
	Type                       int           `json:"type"`
	GuildId                    string        `json:"guild_id"`
	Position                   int           `json:"position"`
	Overwrites                 []interface{} `json:"permission_overwrites"`
	Name                       string        `json:"name"`
	Topic                      string        `json:"topic"`
	NSFW                       bool          `json:"nsfw"`
	LastMessageId              string        `json:"last_message_id"`
	Bitrate                    int           `json:"bitrate"`
	UserLimit                  int           `json:"user_limit"`
	RateLimitPerUser           int           `json:"rate_limit_per_user"`
	Recipients                 []interface{} `json:"recipients"`
	Icon                       string        `json:"icon"`
	OwnerId                    string        `json:"owner_id"`
	ApplicationId              string        `json:"application_id"`
	ParentId                   string        `json:"parent_id"`
	LastPinTime                int           `json:"last_pin_timestamp"`
	RTCRegion                  string        `json:"rtc_region"`
	VideoQualityMode           int           `json:"video_quality_mode"`
	MessageCount               int           `json:"message_count"`
	ThreadMetaData             interface{}   `json:"thread_metadata"`
	Member                     interface{}   `json:"member"`
	DefaultAutoArchiveDuration int           `json:"default_auto_archive_days"`
	Permissions                string        `json:"permissions"`
	Flags                      int           `json:"flags"`
	TotalMessages              int           `json:"total_messages"`
	// contains filtered or unexported fields
}

Channel represents a Discord channel of any type

func (*Channel) Send added in v1.5.1

func (c *Channel) Send(draft Draft) Message

type ChannelType added in v1.5.1

type ChannelType int
const (
	GuildText          ChannelType = 0
	DMText             ChannelType = 1
	GuildVoice         ChannelType = 2
	GroupDM            ChannelType = 3
	GuildCategory      ChannelType = 4
	GuildNews          ChannelType = 5
	GuildNewsThread    ChannelType = 10
	GuildPublicThread  ChannelType = 11
	GuildPrivateThread ChannelType = 12
	GuildStageVoice    ChannelType = 13
	GuildDirectory     ChannelType = 14
	GuildForum         ChannelType = 15
)

type Choice

type Choice struct {
	Name  string      `json:"name"`
	Value interface{} `json:"value"` // same type as type of option
}

type CommandType added in v1.5.1

type CommandType int
const (
	SlashCommand   CommandType = 1
	UserCommand    CommandType = 2
	MessageCommand CommandType = 3
)

type Component

type Component struct {
	CustomId string   `json:"custom_id"`
	Type     int      `json:"type"`
	Value    string   `json:"value"`
	Values   []string `json:"values"`
}

type ComponentData

type ComponentData struct {
	ComponentType int      `json:"component_type"`
	CustomId      string   `json:"custom_id"`
	Values        []string `json:"values"`
	Components    []Row    `json:"components"`
}

type Context

type Context struct {
	Id             string `json:"id"`
	ApplicationId  string `json:"application_id"`
	Type           int    `json:"type"`
	Data           Data   `json:"data"`
	GuildId        string `json:"guild_id"`
	ChannelId      string `json:"channel_id"`
	User           User   `json:"user"`
	Token          string `json:"token"`
	Version        int    `json:"version"`
	AppPermissions string `json:"app_permissions"`
	Locale         string `json:"locale"`
	GuildLocale    string `json:"guild_locale"`
	TargetUser     User
	TargetMessage  Message
	Channel        Channel
	Guild          Guild
	Author         Member
	// contains filtered or unexported fields
}

func (*Context) Defer

func (c *Context) Defer(ephemeral bool)

func (*Context) Delete

func (c *Context) Delete()

func (*Context) Edit

func (c *Context) Edit(resp Response)

func (*Context) OriginalResponse added in v1.5.1

func (c *Context) OriginalResponse() Message

func (*Context) Send

func (c *Context) Send(resp Response)

func (*Context) SendFollowup

func (c *Context) SendFollowup(resp Response) Followup

func (*Context) SendModal

func (c *Context) SendModal(modal Modal)

type Converter added in v1.5.1

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

func (Converter) Attachment added in v1.5.1

func (c Converter) Attachment() *Attachment

func (Converter) Bot added in v1.5.1

func (c Converter) Bot() *BotUser

func (Converter) Channel added in v1.5.1

func (c Converter) Channel() *Channel

func (Converter) Embed added in v1.5.1

func (c Converter) Embed() *Embed

func (Converter) Emoji added in v1.5.1

func (c Converter) Emoji() *Emoji

func (Converter) Guild added in v1.5.1

func (c Converter) Guild() *Guild

func (Converter) Member added in v1.5.1

func (c Converter) Member() *Member

func (Converter) Message added in v1.5.1

func (c Converter) Message() *Message

func (Converter) Role added in v1.5.1

func (c Converter) Role() *Role

func (Converter) User added in v1.5.1

func (c Converter) User() *User

type Data added in v1.5.1

type Data struct {
	Id       string                 `json:"id"`
	Name     string                 `json:"name"`
	Type     int                    `json:"type"`
	Resolved map[string]interface{} `json:"resolved"`
	Options  []Option               `json:"options"`
	GuildId  string                 `json:"guild_id"`
	TargetId string                 `json:"target_id"`
}

type Draft added in v1.5.1

type Draft struct {
	Content string
	Embed   Embed
	Embeds  []Embed
	//AllowedMentions []string
	TTS            bool
	View           View
	File           File
	Files          []File
	SuppressEmbeds bool
	Reference      any
	DeleteAfter    float64
}

type Embed

type Embed struct {
	Title       string       `json:"title"`
	Description string       `json:"description"`
	Url         string       `json:"url"`
	Timestamp   string       `json:"timestamp"`
	Color       int          `json:"color"`
	Footer      EmbedFooter  `json:"footer"`
	Author      EmbedAuthor  `json:"author"`
	Image       EmbedImage   `json:"image"`
	Thumbnail   EmbedImage   `json:"thumbnail"`
	Fields      []EmbedField `json:"fields"`
}

func (*Embed) Marshal

func (e *Embed) Marshal() map[string]interface{}

type EmbedAuthor

type EmbedAuthor struct {
	Name    string `json:"name"`
	IconUrl string `json:"icon_url"`
}

type EmbedField

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

type EmbedFooter

type EmbedFooter struct {
	Text    string `json:"text"`
	IconUrl string `json:"icon_url"`
}

type EmbedImage

type EmbedImage struct {
	Url    string `json:"url"`
	Height int    `json:"height"`
	Width  int    `json:"width"`
}

type Emoji

type Emoji struct {
	Id            int64    `json:"id,string"`
	Name          string   `json:"name"`
	Roles         []string `json:"roles"`
	Managed       bool     `json:"managed"`
	Animated      bool     `json:"animated"`
	Available     bool     `json:"available"`
	RequireColons bool     `json:"require_colons"`
}

type File

type File struct {
	Name        string
	Content     []byte
	Description string
}

func (*File) AddContent

func (f *File) AddContent(path string)

type Followup added in v1.5.1

type Followup struct {
	Id        string
	Content   string
	Embeds    []Embed
	ChannelId string
	Flags     int
	// contains filtered or unexported fields
}

func (*Followup) Delete added in v1.5.1

func (f *Followup) Delete()

func (*Followup) Edit added in v1.5.1

func (f *Followup) Edit(resp Response) Followup

type Guild

type Guild struct {
	Id                          string                   `json:"id"`
	Name                        string                   `json:"name"`
	Owner                       bool                     `json:"owner"`
	OwnerID                     string                   `json:"owner_id"`
	Permissions                 string                   `json:"permissions"`
	Region                      string                   `json:"region"`
	AfkChannelID                string                   `json:"afk_channel_id"`
	AfkTimeout                  int                      `json:"afk_timeout"`
	WidgetEnabled               bool                     `json:"widget_enabled"`
	WidgetChannelID             string                   `json:"widget_channel_id"`
	VerificationLevel           int                      `json:"verification_level"`
	DefaultMessageNotifications int                      `json:"default_message_notifications"`
	ExplicitContentFilter       int                      `json:"explicit_content_filter"`
	Emojis                      []Emoji                  `json:"emojis"`
	Features                    []string                 `json:"features"`
	MFALevel                    int                      `json:"mfa_level"`
	ApplicationID               string                   `json:"application_id"`
	SystemChannelID             string                   `json:"system_channel_id"`
	SystemChannelFlags          int                      `json:"system_channel_flags"`
	RulesChannelID              string                   `json:"rules_channel_id"`
	MaxPresences                int                      `json:"max_presences"`
	MaxMembers                  int                      `json:"max_members"`
	VanityURLCode               string                   `json:"vanity_url_code"`
	Description                 string                   `json:"description"`
	PremiumTier                 int                      `json:"premium_tier"`
	PremiumSubscriptionCount    int                      `json:"premium_subscription_count"`
	PreferredLocale             string                   `json:"preferred_locale"`
	PublicUpdatesChannelID      string                   `json:"public_updates_channel_id"`
	MaxVideoChannelUsers        int                      `json:"max_video_channel_users"`
	ApproximateMemberCount      int                      `json:"approximate_member_count"`
	ApproximatePresenceCount    int                      `json:"approximate_presence_count"`
	WelcomeScreen               map[string]interface{}   `json:"welcome_screen_enabled"`
	NSFWLevel                   int                      `json:"nsfw_level"`
	Stickers                    map[string]interface{}   `json:"stickers"`
	PremiumProgressBarEnabled   bool                     `json:"premium_progress_bar_enabled"`
	JoinedAT                    string                   `json:"joined_at"`
	Large                       bool                     `json:"large"`
	MemberCount                 int                      `json:"member_count"`
	VoiceStates                 []map[string]interface{} `json:"voice_states"`
	Presences                   []map[string]interface{} `json:"presences"`
	Threads                     []map[string]interface{} `json:"threads"`
	StageInstances              []map[string]interface{} `json:"stage_instances"`
	Unavailable                 bool                     `json:"unavailable"`
	GuildScheduledEvents        []map[string]interface{} `json:"guild_scheduled_events"`

	Icon            Asset
	Banner          Asset
	Splash          Asset //    `json:"splash"`
	DiscoverySplash Asset //    `json:"discovery_splash"`
	Me              *Member
	Roles           map[string]*Role
	Members         map[string]*Member
	Channels        map[string]*Channel
	// contains filtered or unexported fields
}

type Intent added in v1.5.1

type Intent int
const (
	GuildsIntent                Intent = 1 << 0
	GuildMembersIntent          Intent = 1 << 1
	GuildBansIntent             Intent = 1 << 2
	GuildEmojisIntent           Intent = 1 << 3
	GuildIntegrationsIntent     Intent = 1 << 4
	GuildWebhooksIntent         Intent = 1 << 5
	GuildInvitesIntent          Intent = 1 << 6
	GuildVoiceStatesIntent      Intent = 1 << 7
	GuildPresencesIntent        Intent = 1 << 8
	GuildMessagesIntent         Intent = 1 << 9
	GuildMessageReactionsIntent Intent = 1 << 10
	GuildMessageTypingIntent    Intent = 1 << 11
	DMIntent                    Intent = 1 << 12
	DMReactionsIntent           Intent = 1 << 13
	DMTypingIntent              Intent = 1 << 14
	MessageContentIntent        Intent = 1 << 15
	GuildScheduleEventsIntent   Intent = 1 << 16
	AutoModConfigIntent         Intent = 1 << 17
	AutoModExecuteIntent        Intent = 1 << 18
)

func Intents

func Intents(intents ...Intent) Intent

type Member

type Member struct {
	Nickname      string           `json:"nick"`
	AvatarHash    string           `json:"avatar"`
	JoinedAt      string           `json:"joined_at"`
	PremiumSince  string           `json:"premium_since"`
	Deaf          bool             `json:"deaf"`
	Mute          bool             `json:"mute"`
	Pending       bool             `json:"pending"`
	Permissions   string           `json:"permissions"`
	TimeoutExpiry string           `json:"communication_disabled_until"`
	GuildId       string           `json:"guild_id"`
	Roles         map[string]*Role `json:"roles"`

	Id            string
	Name          string
	Discriminator string
	Avatar        Asset
	Bot           bool
	System        bool
	MfaEnabled    bool
	Banner        Asset
	Color         int
	Locale        string
	Verified      bool
	Email         string
	Flags         int
	PremiumType   int
	PublicFlags   int
	// contains filtered or unexported fields
}

func (*Member) HasPermissions added in v1.5.1

func (m *Member) HasPermissions(permissions ...Permission) bool

type Message

type Message struct {
	Id                 string                   `json:"id"`
	ChannelId          string                   `json:"channel_id"`
	Author             User                     `json:"author"`
	Content            string                   `json:"content"`
	Timestamp          string                   `json:"timestamp"`
	EditedTimestamp    string                   `json:"edited_timestamp"`
	TTS                bool                     `json:"tts"`
	MentionEveryone    bool                     `json:"mention_everyone"`
	Mentions           []map[string]interface{} `json:"mentions"`
	RoleMentions       []string                 `json:"role_mentions"`
	ChannelMentions    []string                 `json:"channel_mentions"`
	Attachments        []map[string]interface{} `json:"attachments"`
	Embeds             []Embed                  `json:"embeds"`
	Reactions          []map[string]interface{} `json:"reactions"`
	Pinned             bool                     `json:"pinned"`
	WebhookId          string                   `json:"webhook_id"`
	Type               int                      `json:"types"`
	Activity           map[string]interface{}   `json:"activity"`
	Application        map[string]interface{}   `json:"application"`
	ApplicationId      string                   `json:"application_id"`
	MessageReference   map[string]interface{}   `json:"message_reference"`
	Flags              int                      `json:"flags"`
	ReferencedMessages map[string]interface{}   `json:"reference"`
	Interaction        map[string]interface{}   `json:"interaction"`
	Thread             map[string]interface{}   `json:"thread"`
	Components         []map[string]interface{} `json:"components"`
	Stickers           []map[string]interface{} `json:"sticker_items"`
	// contains filtered or unexported fields
}

func (*Message) Delete added in v1.5.1

func (m *Message) Delete()

func (*Message) Reply added in v1.5.1

func (m *Message) Reply(draft Draft) Message
type Modal struct {
	Title       string
	CustomId    string // filled internally
	Fields      []TextInput
	SelectMenus []SelectMenu
}

func (*Modal) OnSubmit

func (m *Modal) OnSubmit(handler func(bot BotUser, ctx Context))

type Option added in v1.5.1

type Option struct {
	Name         string      `json:"name"`
	Type         OptionType  `json:"type"`
	Value        interface{} `json:"value"`   // available only during option parsing
	Focused      bool        `json:"focused"` // available only during option parsing
	Description  string
	Required     bool
	MinLength    int           // allowed for: StringOption
	MaxLength    int           // allowed for: StringOption
	MinValue     int64         // allowed for: IntegerOption, NumberOption
	MaxValue     int64         // allowed for: IntegerOption, NumberOption
	AutoComplete bool          // allowed for: StringOption, NumberOption, IntegerOption
	ChannelTypes []ChannelType // allowed for: ChannelOption
	Choices      []Choice      // allowed for: StringOption, IntegerOption, NumberOption
}

type OptionType added in v1.5.1

type OptionType int
const (
	StringOption      OptionType = 3
	IntegerOption     OptionType = 4
	BooleanOption     OptionType = 5
	UserOption        OptionType = 6
	ChannelOption     OptionType = 7
	RoleOption        OptionType = 8
	MentionableOption OptionType = 9
	NumberOption      OptionType = 10
	AttachmentOption  OptionType = 11
)

type PartialAttachment

type PartialAttachment struct {
	Id          string `json:"id"`
	Filename    string `json:"filename"`
	Description string `json:"description"`
}

PartialAttachment represents a partial Discord attachment

type PartialEmoji

type PartialEmoji struct {
	Id       string `json:"id"`
	Name     string `json:"name"`
	Animated bool   `json:"animated,omitempty"`
}

type Permission added in v1.5.1

type Permission int

type Presence

type Presence struct {
	Since    int64
	Status   string // "online" or "idle" or "dnd" or "offline" or "invisible"
	AFK      bool
	Activity Activity // base activity object
	OnMobile bool
}

func (*Presence) Marshal

func (p *Presence) Marshal() map[string]interface{}

type Response

type Response struct {
	Content         string
	Embed           Embed
	Embeds          []Embed
	AllowedMentions []string
	TTS             bool
	Ephemeral       bool
	SuppressEmbeds  bool
	View            View
	File            File
	Files           []File
}

func (*Response) Marshal

func (resp *Response) Marshal() map[string]interface{}

type Role

type Role struct {
	Id           string `json:"id"`
	Name         string `json:"name"`
	Color        int    `json:"color"`
	Hoist        bool   `json:"hoist"`
	Icon         string `json:"icon"`
	UnicodeEmoji bool   `json:"unicode_emoji"`
	Position     int    `json:"position"`
	Permissions  string `json:"permissions"`
	Managed      bool   `json:"managed"`
	Mentionable  bool   `json:"mentionable"`
	Tags         string `json:"tags"`
	GuildId      string `json:"guild_id"`
}

type Row

type Row struct {
	Components []Component
}

type SelectMenu

type SelectMenu struct {
	Options     []SelectOption // max 25 options
	Placeholder string         // max 100 characters
	MinValues   int            // default: 0
	MaxValues   int            // default: 1
	Disabled    bool
	OnSelection func(bot BotUser, comp Context, values ...string)
	// contains filtered or unexported fields
}

type SelectOption

type SelectOption struct {
	Label       string // max 100 characters
	Value       string // default: ""
	Description string // max 100 characters
	Emoji       PartialEmoji
	Default     bool // default: false
}

type SubCommand added in v1.5.1

type SubCommand struct {
	Name        string
	Description string
	Options     []Option
	Task        func(bot BotUser, ctx Context, options map[string]Option)
}

type SubcommandGroup added in v1.5.1

type SubcommandGroup struct {
	Name        string
	Description string
	// contains filtered or unexported fields
}

func (*SubcommandGroup) Subcommands added in v1.5.1

func (scg *SubcommandGroup) Subcommands(subcommands ...SubCommand)

type TextInput

type TextInput struct {
	CustomId    string `json:"custom_id"`   // filled internally
	Label       string `json:"label"`       // required default: "Text Input"
	Style       int    `json:"style"`       // 1 for short, 2 for long default: 1
	Value       string `json:"value"`       // default: ""
	Placeholder string `json:"placeholder"` // max 100 chars
	MinLength   int    `json:"min_length"`  // default: 0 upto 4000
	MaxLength   int    `json:"max_length"`  // default: 0 upto 4000
	Required    bool   `json:"required"`    // default: false
}

type User

type User struct {
	Id            string `json:"id"`
	Username      string `json:"username"`
	Discriminator string `json:"discriminator"`
	Bot           bool   `json:"bot"`
	System        bool   `json:"system"`
	MfaEnabled    bool   `json:"mfa_enabled"`
	Color         int    `json:"accent_color"`
	Locale        string `json:"locale"`
	Verified      bool   `json:"verified"`
	Email         string `json:"email"`
	Flags         int    `json:"flags"`
	PremiumType   int    `json:"premium_type"`
	PublicFlags   int    `json:"public_flags"`

	Avatar Asset
	Banner Asset
	// contains filtered or unexported fields
}

type View

type View struct {
	Timeout    float64     // default: 15 * 60 seconds
	ActionRows []ActionRow // max 5 rows
	OnTimeout  func(bot BotUser, ctx Context)
}

func (*View) AddButtons

func (v *View) AddButtons(buttons ...Button)

func (*View) AddRow

func (v *View) AddRow(row ActionRow)

func (*View) AddSelectMenu

func (v *View) AddSelectMenu(menu SelectMenu)

Jump to

Keyboard shortcuts

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