discord

package
v0.7.3 Latest Latest
Warning

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

Go to latest
Published: May 13, 2020 License: ISC Imports: 8 Imported by: 33

Documentation

Overview

Package discord provides common structures that the whole repository uses. It does not (and should not) contain API-specific structures, or WS-specific structures.

Index

Constants

View Source
const DefaultMaxPresences = 5000

Guild.MaxPresences is 5000 when it's 0.

View Source
const DiscordEpoch = 1420070400000 * time.Millisecond

DiscordEpoch is the Discord epoch constant in time.Duration (nanoseconds) since Unix epoch.

View Source
const NullSecond = -1

NullSecond is used in cases where null should be used instead of a number or omitted. This is similar to NullSnowflake.

View Source
const TimestampFormat = time.RFC3339 // same as ISO8601

Variables

View Source
var DefaultAvatarURL = "https://discordapp.com/assets/dd4dbc0016779df1378e7812eabaa04d.png"

DefaultAvatarURL is the link to the default green avatar on Discord. It's returned from AvatarURL() if the user doesn't have an avatar.

Functions

func DurationSinceDiscordEpoch added in v0.7.0

func DurationSinceDiscordEpoch(t time.Time) time.Duration

DurationSinceDiscordEpoch returns the duration from the Discord epoch to current.

func HasFlag added in v0.6.2

func HasFlag(flag, has uint64) bool

HasFlag is returns true if has is in the flag. In other words, it checks if has is OR'd into flag. This function could be used for different constants such as Permission.

Types

type Activity

type Activity struct {
	Name string       `json:"name"`
	Type ActivityType `json:"type"`
	URL  URL          `json:"url,omitempty"`

	CreatedAt  UnixTimestamp      `json:"created_at,omitempty"`
	Timestamps *ActivityTimestamp `json:"timestamps,omitempty"`

	ApplicationID Snowflake `json:"application_id,omitempty"`
	Details       string    `json:"details,omitempty"`
	State         string    `json:"state,omitempty"` // party status
	Emoji         *Emoji    `json:"emoji,omitempty"`

	Party   *ActivityParty   `json:"party,omitempty"`
	Assets  *ActivityAssets  `json:"assets,omitempty"`
	Secrets *ActivitySecrets `json:"secrets,omitempty"`

	Instance bool          `json:"instance,omitempty"`
	Flags    ActivityFlags `json:"flags,omitempty"`

	// Undocumented fields
	SyncID    string `json:"sync_id,omitempty"`
	SessionID string `json:"session_id,omitempty"`
}

type ActivityAssets added in v0.2.0

type ActivityAssets struct {
	LargeImage string `json:"large_image,omitempty"` // id
	LargeText  string `json:"large_text,omitempty"`
	SmallImage string `json:"small_image,omitempty"` // id
	SmallText  string `json:"small_text,omitempty"`
}

type ActivityFlags

type ActivityFlags uint32
const (
	InstanceActivity ActivityFlags = 1 << iota
	JoinActivity
	SpectateActivity
	JoinRequestActivity
	SyncActivity
	PlayActivity
)

type ActivityParty added in v0.2.0

type ActivityParty struct {
	ID   string `json:"id,omitempty"`
	Size [2]int `json:"size,omitempty"` // [ current, max ]
}

type ActivitySecrets added in v0.2.0

type ActivitySecrets struct {
	Join     string `json:"join,omitempty"`
	Spectate string `json:"spectate,omitempty"`
	Match    string `json:"match,omitempty"`
}

type ActivityTimestamp added in v0.2.0

type ActivityTimestamp struct {
	Start UnixMsTimestamp `json:"start,omitempty"`
	End   UnixMsTimestamp `json:"end,omitempty"`
}

type ActivityType

type ActivityType uint8
const (
	// Playing $name
	GameActivity ActivityType = iota
	// Streaming $details
	StreamingActivity
	// Listening to $name
	ListeningActivity

	// $emoji $state
	CustomActivity
)

type Attachment

type Attachment struct {
	ID       Snowflake `json:"id,string"`
	Filename string    `json:"filename"`
	Size     uint64    `json:"size"`

	URL   URL `json:"url"`
	Proxy URL `json:"proxy_url"`

	// Only if Image
	Height uint `json:"height,omitempty"`
	Width  uint `json:"width,omitempty"`
}

type AuditEntryInfo added in v0.6.3

type AuditEntryInfo struct {
	// MEMBER_PRUNE
	DeleteMemberDays string `json:"delete_member_days,omitempty"`
	// MEMBER_PRUNE
	MembersRemoved string `json:"members_removed,omitempty"`
	// MEMBER_MOVE & MESSAGE_PIN & MESSAGE_UNPIN & MESSAGE_DELETE
	ChannelID Snowflake `json:"channel_id,omitempty"`
	// MESSAGE_PIN & MESSAGE_UNPIN
	MessageID Snowflake `json:"message_id,omitempty"`
	// MESSAGE_DELETE & MESSAGE_BULK_DELETE & MEMBER_DISCONNECT & MEMBER_MOVE
	Count string `json:"count,omitempty"`
	// CHANNEL_OVERWRITE_CREATE & CHANNEL_OVERWRITE_UPDATE & CHANNEL_OVERWRITE_DELETE
	ID Snowflake `json:"id,omitempty"`
	// CHANNEL_OVERWRITE_CREATE & CHANNEL_OVERWRITE_UPDATE & CHANNEL_OVERWRITE_DELETE
	Type ChannelOverwritten `json:"type,omitempty"`
	// CHANNEL_OVERWRITE_CREATE & CHANNEL_OVERWRITE_UPDATE & CHANNEL_OVERWRITE_DELETE
	RoleName string `json:"role_name,omitempty"`
}

type AuditLog added in v0.6.3

type AuditLog struct {
	// List of webhooks found in the audit log
	Webhooks []Webhook `json:"webhooks"`
	// List of users found in the audit log
	Users []User `json:"users"`
	// List of audit log entries
	Entries []AuditLogEntry `json:"audit_log_entries"`
	// List of partial integration objects, only ID, Name, Type, and Account
	Integrations []Integration `json:"integrations"`
}

type AuditLogChange added in v0.6.3

type AuditLogChange struct {
	Key      string   `json:"key"`
	NewValue json.Raw `json:"new_value,omitempty"` // nullable
	OldValue json.Raw `json:"old_value,omitempty"` // nullable
}

AuditLogChange is a single key type to changed value audit log entry. The type can be found in the key's comment. Values can be nil.

What

I'm glad to see the same reaction that I had on you. In short, in this struct, the Key dictates what type NewValue and OldValue will have. They will always be the same type, but I will leave that as JSON for the user.

Usage

The usage of this is pretty simple, as AuditLogChange already has a convenient method to use. Here's an example on how to do "owner_id":

if change.Key != discord.AuditGuildOwnerID {
    return errors.New("not owner ID")
}

// We know these are snowflakes because the comment said so for AuditGuildOwnerID.
var oldOwnerID, newOwnerID discord.Snowflake
if err := change.UnmarshalValues(&oldOwnerID, &newOwnerID); err != nil {
    return err
}

log.Println("Transferred ownership from user", oldOwnerID, "to", newOwnerID)

func (AuditLogChange) UnmarshalValues added in v0.6.4

func (a AuditLogChange) UnmarshalValues(old, new interface{}) error

type AuditLogChangeKey added in v0.6.3

type AuditLogChangeKey string
const (
	// Type string, name changed
	AuditGuildName AuditLogChangeKey = "name"
	// Type Hash, icon changed
	AuditGuildIconHash AuditLogChangeKey = "icon_hash"
	// Type Hash, invite splash page artwork changed
	AuditGuildSplashHash AuditLogChangeKey = "splash_hash"
	// Type Snowflake, owner changed
	AuditGuildOwnerID AuditLogChangeKey = "owner_id"
	// Type string, region changed
	AuditGuildRegion AuditLogChangeKey = "region"
	// Type Snowflake, afk channel changed
	AuditGuildAFKChannelID AuditLogChangeKey = "afk_channel_id"
	// Type Seconds, afk timeout duration changed
	AuditGuildAFKTimeout AuditLogChangeKey = "afk_timeout"
	// Type int, two-factor auth requirement changed
	AuditGuildMFA AuditLogChangeKey = "mfa_level"
	// Type Verification, required verification level changed
	AuditGuildVerification AuditLogChangeKey = "verification_level"
	// Type ExplicitFilter, change in whose messages are scanned and deleted for
	// explicit content in the server
	AuditGuildExplicitFilter AuditLogChangeKey = "explicit_content_filter"
	// Type Notification, default message notification level changed
	AuditGuildNotification AuditLogChangeKey = "default_message_notifications"
	// Type string, guild invite vanity URL changed
	AuditGuildVanityURLCode AuditLogChangeKey = "vanity_url_code"
	// Type []Role{ID, Name}, new role added
	AuditGuildRoleAdd AuditLogChangeKey = "$add"
	// Type []Role{ID, Name}, role removed
	AuditGuildRoleRemove AuditLogChangeKey = "$remove"
	// Type int, change in number of days after which inactive and
	// role-unassigned members are kicked
	AuditGuildPruneDeleteDays AuditLogChangeKey = "prune_delete_days"
	// Type bool, server widget enabled/disable
	AuditGuildWidgetEnabled AuditLogChangeKey = "widget_enabled"
	// Type Snowflake, channel ID of the server widget changed
	AuditGuildWidgetChannelID AuditLogChangeKey = "widget_channel_id"
	// Type Snowflake, ID of the system channel changed
	AuditGuildSystemChannelID AuditLogChangeKey = "system_channel_id"
)
const (
	// Type int, text or voice channel position changed
	AuditChannelPosition AuditLogChangeKey = "position"
	// Type string, text channel topic changed
	AuditChannelTopic AuditLogChangeKey = "topic"
	// Type uint, voice channel bitrate changed
	AuditChannelBitrate AuditLogChangeKey = "bitrate"
	// Type []Overwrite, permissions on a channel changed
	AuditChannelPermissionOverwrites AuditLogChangeKey = "permission_overwrites"
	// Type bool, channel NSFW restriction changed
	AuditChannelNSFW AuditLogChangeKey = "nsfw"
	// Type Snowflake, application ID of the added or removed webhook or bot
	AuditChannelApplicationID AuditLogChangeKey = "application_id"
	// Type Seconds, amount of seconds a user has to wait before sending another
	// message changed
	AuditChannelRateLimitPerUser AuditLogChangeKey = "rate_limit_per_user"
)
const (
	// Type Permissions, permissions for a role changed
	AuditRolePermissions AuditLogChangeKey = "permissions"
	// Type Color, role color changed
	AuditRoleColor AuditLogChangeKey = "color"
	// Type bool, role is now displayed/no longer displayed separate from online
	// users
	AuditRoleHoist AuditLogChangeKey = "hoist"
	// Type bool, role is now mentionable/unmentionable
	AuditRoleMentionable AuditLogChangeKey = "mentionable"
	// Type Permissions, a permission on a text or voice channel was allowed for
	// a role
	AuditRoleAllow AuditLogChangeKey = "allow"
	// Type Permissions, a permission on a text or voice channel was denied for
	// a role
	AuditRoleDeny AuditLogChangeKey = "deny"
)
const (
	// Type string, invite code changed
	AuditInviteCode AuditLogChangeKey = "code"
	// Type Snowflake, channel for invite code changed
	AuditInviteChannelID AuditLogChangeKey = "channel_id"
	// Type Snowflake, person who created invite code changed
	AuditInviteInviterID AuditLogChangeKey = "inviter_id"
	// Type int, change to max number of times invite code can be used
	AuditInviteMaxUses AuditLogChangeKey = "max_uses"
	// Type int, number of times invite code used changed
	AuditInviteUses AuditLogChangeKey = "uses"
	// Type Seconds, how long invite code lasts changed
	AuditInviteMaxAge AuditLogChangeKey = "max_age"
	// Type bool, invite code is temporary/never expires
	AuditInviteTemporary AuditLogChangeKey = "temporary"
)
const (
	// Type bool, user server deafened/undeafened
	AuditUserDeaf AuditLogChangeKey = "deaf"
	// Type bool, user server muted/unmuted
	AuditUserMute AuditLogChangeKey = "mute"
	// Type string, user nickname changed
	AuditUserNick AuditLogChangeKey = "nick"
	// Type Hash, user avatar changed
	AuditUserAvatarHash AuditLogChangeKey = "avatar_hash"
)
const (
	// Type Snowflake, the ID of the changed entity - sometimes used in
	// conjunction with other keys
	AuditAnyID AuditLogChangeKey = "id"
	// Type int (channel type) or string, type of entity created
	AuditAnyType AuditLogChangeKey = "type"
)
const (
	// Type bool, integration emoticons enabled/disabled
	AuditIntegrationEnableEmoticons AuditLogChangeKey = "enable_emoticons"
	// Type int, integration expiring subscriber behavior changed
	AuditIntegrationExpireBehavior AuditLogChangeKey = "expire_behavior"
	// Type int, integration expire grace period changed
	AuditIntegrationExpireGracePeriod AuditLogChangeKey = "expire_grace_period"
)

type AuditLogEntry added in v0.6.4

type AuditLogEntry struct {
	ID       Snowflake `json:"id"`
	UserID   Snowflake `json:"user_id"`
	TargetID string    `json:"target_id,omitempty"`

	ActionType AuditLogEvent `json:"action_type"`

	Changes []AuditLogChange `json:"changes,omitempty"`
	Options AuditEntryInfo   `json:"options,omitempty"`
	Reason  string           `json:"reason,omitempty"`
}

AuditLogEntry is a single entry in the audit log.

type AuditLogEvent added in v0.6.3

type AuditLogEvent uint8

AuditLogEvent is the type of audit log action that occured.

const (
	GuildUpdate            AuditLogEvent = 1
	ChannelCreate          AuditLogEvent = 10
	ChannelUpdate          AuditLogEvent = 11
	ChannelDelete          AuditLogEvent = 12
	ChannelOverwriteCreate AuditLogEvent = 13
	ChannelOverwriteUpdate AuditLogEvent = 14
	ChannelOverwriteDelete AuditLogEvent = 15
	MemberKick             AuditLogEvent = 20
	MemberPrune            AuditLogEvent = 21
	MemberBanAdd           AuditLogEvent = 22
	MemberBanRemove        AuditLogEvent = 23
	MemberUpdate           AuditLogEvent = 24
	MemberRoleUpdate       AuditLogEvent = 25
	MemberMove             AuditLogEvent = 26
	MemberDisconnect       AuditLogEvent = 27
	BotAdd                 AuditLogEvent = 28
	RoleCreate             AuditLogEvent = 30
	RoleUpdate             AuditLogEvent = 31
	RoleDelete             AuditLogEvent = 32
	InviteCreate           AuditLogEvent = 40
	InviteUpdate           AuditLogEvent = 41
	InviteDelete           AuditLogEvent = 42
	WebhookCreate          AuditLogEvent = 50
	WebhookUpdate          AuditLogEvent = 51
	WebhookDelete          AuditLogEvent = 52
	EmojiCreate            AuditLogEvent = 60
	EmojiUpdate            AuditLogEvent = 61
	EmojiDelete            AuditLogEvent = 62
	MessageDelete          AuditLogEvent = 72
	MessageBulkDelete      AuditLogEvent = 73
	MessagePin             AuditLogEvent = 74
	MessageUnpin           AuditLogEvent = 75
	IntegrationCreate      AuditLogEvent = 80
	IntegrationUpdate      AuditLogEvent = 81
	IntegrationDelete      AuditLogEvent = 82
)

type Ban

type Ban struct {
	Reason string `json:"reason,omitempty"`
	User   User   `json:"user"`
}

type Channel

type Channel struct {
	ID   Snowflake   `json:"id,string"`
	Type ChannelType `json:"type"`

	GuildID Snowflake `json:"guild_id,string,omitempty"`

	Position int    `json:"position,omitempty"`
	Name     string `json:"name,omitempty"`  // 2-100 chars
	Topic    string `json:"topic,omitempty"` // 0-1024 chars
	NSFW     bool   `json:"nsfw"`

	Icon Hash `json:"icon,omitempty"`

	// Direct Messaging fields
	DMOwnerID    Snowflake `json:"owner_id,string,omitempty"`
	DMRecipients []User    `json:"recipients,omitempty"`

	// AppID of the group DM creator if it's bot-created
	AppID Snowflake `json:"application_id,string,omitempty"`

	// ID of the category the channel is in, if any.
	CategoryID Snowflake `json:"parent_id,string,omitempty"`

	LastPinTime Timestamp `json:"last_pin_timestamp,omitempty"`

	// Explicit permission overrides for members and roles.
	Permissions []Overwrite `json:"permission_overwrites,omitempty"`
	// ID of the last message, may not point to a valid one.
	LastMessageID Snowflake `json:"last_message_id,string,omitempty"`

	// Slow mode duration. Bots and people with "manage_messages" or
	// "manage_channel" permissions are unaffected.
	UserRateLimit Seconds `json:"rate_limit_per_user,omitempty"`

	// Voice, so GuildVoice only
	VoiceBitrate   uint `json:"bitrate,omitempty"`
	VoiceUserLimit uint `json:"user_limit,omitempty"`
}

func (Channel) IconURL added in v0.2.0

func (ch Channel) IconURL() string

IconURL returns the icon of the channel. This function will only return something if ch.Icon is not empty.

func (Channel) Mention added in v0.0.11

func (ch Channel) Mention() string

type ChannelMention

type ChannelMention struct {
	ChannelID   Snowflake   `json:"id,string"`
	GuildID     Snowflake   `json:"guild_id,string"`
	ChannelType ChannelType `json:"type"`
	ChannelName string      `json:"name"`
}

type ChannelOverwritten added in v0.6.3

type ChannelOverwritten string

ChannelOverwritten is the type of overwritten entity in (AuditEntryInfo).Type.

const (
	MemberChannelOverwritten ChannelOverwritten = "member"
	RoleChannelOverwritten   ChannelOverwritten = "role"
)

type ChannelType

type ChannelType uint8
var (
	GuildText     ChannelType = 0
	DirectMessage ChannelType = 1
	GuildVoice    ChannelType = 2
	GroupDM       ChannelType = 3
	GuildCategory ChannelType = 4
	GuildNews     ChannelType = 5
	GuildStore    ChannelType = 6
)

type Color

type Color uint32
var DefaultEmbedColor Color = 0x303030
var DefaultMemberColor Color = 0x0

DefaultMemberColor is the color used for members without colored roles.

func MemberColor added in v0.0.7

func MemberColor(guild Guild, member Member) Color

func (Color) Int added in v0.0.7

func (c Color) Int() int

func (Color) RGB added in v0.1.5

func (c Color) RGB() (uint8, uint8, uint8)

RGB splits Color into red, green, and blue. The maximum value is 255.

func (Color) Uint32 added in v0.0.7

func (c Color) Uint32() uint32

type Connection

type Connection struct {
	ID   Snowflake `json:"id"`
	Name string    `json:"name"`
	Type Service   `json:"type"`

	Revoked      bool `json:"revoked"`
	Verified     bool `json:"verified"`
	FriendSync   bool `json:"friend_sync"`
	ShowActivity bool `json:"show_activity"`

	Visibility ConnectionVisibility `json:"visibility"`

	// Only partial
	Integrations []Integration `json:"integrations"`
}

type ConnectionVisibility

type ConnectionVisibility uint8
const (
	ConnectionNotVisible ConnectionVisibility = iota
	ConnectionVisibleEveryone
)

type Embed

type Embed struct {
	Title       string    `json:"title,omitempty"`
	Type        EmbedType `json:"type,omitempty"`
	Description string    `json:"description,omitempty"`

	URL URL `json:"url,omitempty"`

	Timestamp Timestamp `json:"timestamp,omitempty"`
	Color     Color     `json:"color,omitempty"`

	Footer    *EmbedFooter    `json:"footer,omitempty"`
	Image     *EmbedImage     `json:"image,omitempty"`
	Thumbnail *EmbedThumbnail `json:"thumbnail,omitempty"`
	Video     *EmbedVideo     `json:"video,omitempty"`
	Provider  *EmbedProvider  `json:"provider,omitempty"`
	Author    *EmbedAuthor    `json:"author,omitempty"`
	Fields    []EmbedField    `json:"fields,omitempty"`
}

func NewEmbed

func NewEmbed() *Embed

func (*Embed) Validate

func (e *Embed) Validate() error

type EmbedAuthor

type EmbedAuthor struct {
	Name      string `json:"name,omitempty"`
	URL       URL    `json:"url,omitempty"`
	Icon      URL    `json:"icon_url,omitempty"`
	ProxyIcon URL    `json:"proxy_icon_url,omitempty"`
}

type EmbedField

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

type EmbedFooter

type EmbedFooter struct {
	Text      string `json:"text"`
	Icon      URL    `json:"icon_url,omitempty"`
	ProxyIcon URL    `json:"proxy_icon_url,omitempty"`
}

type EmbedImage

type EmbedImage struct {
	URL    URL  `json:"url"`
	Proxy  URL  `json:"proxy_url"`
	Height uint `json:"height,omitempty"`
	Width  uint `json:"width,omitempty"`
}

type EmbedProvider

type EmbedProvider struct {
	Name string `json:"name"`
	URL  URL    `json:"url"`
}

type EmbedThumbnail

type EmbedThumbnail struct {
	URL    URL  `json:"url,omitempty"`
	Proxy  URL  `json:"proxy_url,omitempty"`
	Height uint `json:"height,omitempty"`
	Width  uint `json:"width,omitempty"`
}

type EmbedType

type EmbedType string
const (
	NormalEmbed  EmbedType = "rich"
	ImageEmbed   EmbedType = "image"
	VideoEmbed   EmbedType = "video"
	GIFVEmbed    EmbedType = "gifv"
	ArticleEmbed EmbedType = "article"
	LinkEmbed    EmbedType = "link"
)

type EmbedVideo

type EmbedVideo struct {
	URL    URL  `json:"url"`
	Height uint `json:"height"`
	Width  uint `json:"width"`
}

type Emoji

type Emoji struct {
	ID   Snowflake `json:"id,string"` // 0 for Unicode emojis
	Name string    `json:"name"`

	RoleIDs []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"`
}

func (Emoji) APIString

func (e Emoji) APIString() string

APIString returns a string usable for sending over to the API.

func (Emoji) String

func (e Emoji) String() string

String formats the string like how the client does.

type ErrOverbound

type ErrOverbound struct {
	Count int
	Max   int

	Thing string
}

func (ErrOverbound) Error

func (e ErrOverbound) Error() string

type ExpireBehavior added in v0.7.0

type ExpireBehavior uint8

ExpireBehavior is the integration expire behavior that regulates what happens, if a subscriber expires.

var (
	// RemoveRole removes the role of the subscriber.
	RemoveRole ExpireBehavior = 0
	// Kick kicks the subscriber from the guild.
	Kick ExpireBehavior = 1
)

type ExplicitFilter

type ExplicitFilter enum.Enum

ExplicitFilter is the explicit content filter level of a guild.

var (
	// NullExplicitFilter serialized to JSON null.
	// This should only be used on nullable fields.
	NullExplicitFilter ExplicitFilter = enum.Null
	// NoContentFilter disables content filtering for the guild.
	NoContentFilter ExplicitFilter = 0
	// MembersWithoutRoles filters only members without roles.
	MembersWithoutRoles ExplicitFilter = 1
	// AllMembers enables content filtering for all members.
	AllMembers ExplicitFilter = 2
)

func (ExplicitFilter) MarshalJSON added in v0.7.0

func (f ExplicitFilter) MarshalJSON() ([]byte, error)

func (*ExplicitFilter) UnmarshalJSON added in v0.7.0

func (f *ExplicitFilter) UnmarshalJSON(b []byte) error

type Guild

type Guild struct {
	ID     Snowflake `json:"id,string"`
	Name   string    `json:"name"`
	Icon   Hash      `json:"icon"`
	Splash Hash      `json:"splash,omitempty"` // server invite bg

	Owner   bool      `json:"owner,omitempty"` // self is owner
	OwnerID Snowflake `json:"owner_id,string"`

	Permissions Permissions `json:"permissions,omitempty"`

	VoiceRegion string `json:"region"`

	AFKChannelID Snowflake `json:"afk_channel_id,string,omitempty"`
	AFKTimeout   Seconds   `json:"afk_timeout"`

	Embeddable     bool      `json:"embed_enabled,omitempty"`
	EmbedChannelID Snowflake `json:"embed_channel_id,string,omitempty"`

	Verification   Verification   `json:"verification_level"`
	Notification   Notification   `json:"default_message_notifications"`
	ExplicitFilter ExplicitFilter `json:"explicit_content_filter"`

	Roles    []Role         `json:"roles"`
	Emojis   []Emoji        `json:"emojis"`
	Features []GuildFeature `json:"guild_features"`

	MFA MFALevel `json:"mfa"`

	AppID Snowflake `json:"application_id,string,omitempty"`

	Widget bool `json:"widget_enabled,omitempty"`

	WidgetChannelID Snowflake `json:"widget_channel_id,string,omitempty"`
	SystemChannelID Snowflake `json:"system_channel_id,string,omitempty"`

	// It's DefaultMaxPresences when MaxPresences is 0.
	MaxPresences uint64 `json:"max_presences,omitempty"`
	MaxMembers   uint64 `json:"max_members,omitempty"`

	VanityURLCode string `json:"vanity_url_code,omitempty"`
	Description   string `json:"description,omitempty"`
	Banner        Hash   `json:"banner,omitempty"`

	NitroBoost    NitroBoost `json:"premium_tier"`
	NitroBoosters uint64     `json:"premium_subscription_count,omitempty"`

	// Defaults to en-US, only set if guild has DISCOVERABLE
	PreferredLocale string `json:"preferred_locale"`

	// Only presented if WithCounts is true.
	ApproximateMembers   uint64 `json:"approximate_member_count,omitempty"`
	ApproximatePresences uint64 `json:"approximate_presence_count,omitempty"`
}

func (Guild) BannerURL added in v0.1.1

func (g Guild) BannerURL() string

BannerURL returns the URL to the banner, which is the image on top of the channels list.

func (Guild) IconURL added in v0.1.1

func (g Guild) IconURL() string

IconURL returns the URL to the guild icon. An empty string is removed if there's no icon.

func (Guild) SplashURL added in v0.1.1

func (g Guild) SplashURL() string

SplashURL returns the URL to the guild splash, which is the invite page's background.

type GuildEmbed

type GuildEmbed struct {
	Enabled   bool      `json:"enabled"`
	ChannelID Snowflake `json:"channel_id,omitempty"`
}

type GuildFeature

type GuildFeature string
const (
	// Guild has access to set an invite splash background
	InviteSplash GuildFeature = "INVITE_SPLASH"
	// Guild has access to set 384kbps bitrate in voice (previously VIP voice
	// servers)
	VIPRegions GuildFeature = "VIP_REGIONS"
	// Guild has access to set a vanity URL
	VanityURL GuildFeature = "VANITY_URL"
	// Guild is verified
	Verified GuildFeature = "VERIFIED"
	// Guild is partnered
	Partnered GuildFeature = "PARTNERED"
	// Guild is public
	Public GuildFeature = "PUBLIC"
	// Guild has access to use commerce features (i.e. create store channels)
	Commerce GuildFeature = "COMMERCE"
	// Guild has access to create news channels
	News GuildFeature = "NEWS"
	// Guild is able to be discovered in the directory
	Discoverable GuildFeature = "DISCOVERABLE"
	// Guild is able to be featured in the directory
	Featurable GuildFeature = "FEATURABLE"
	// Guild has access to set an animated guild icon
	AnimatedIcon GuildFeature = "ANIMATED_ICON"
	Banner GuildFeature = "BANNER"
)

type GuildUser

type GuildUser struct {
	User
	Member *Member `json:"member,omitempty"`
}

type Hash

type Hash = string

type Integration

type Integration struct {
	ID   Snowflake `json:"id"`
	Name string    `json:"name"`
	Type Service   `json:"type"`

	Enabled bool `json:"enabled"`
	Syncing bool `json:"syncing"`

	// used for subscribers
	RoleID Snowflake `json:"role_id"`

	ExpireBehavior    ExpireBehavior `json:"expire_behavior"`
	ExpireGracePeriod int            `json:"expire_grace_period"`

	User    User `json:"user"`
	Account struct {
		ID   string `json:"id"`
		Name string `json:"name"`
	} `json:"account"`

	SyncedAt Timestamp `json:"synced_at"`
}

type Invite

type Invite struct {
	Code    string  `json:"code"`
	Channel Channel `json:"channel"`         // partial
	Guild   *Guild  `json:"guild,omitempty"` // partial
	Inviter *User   `json:"inviter,omitempty"`

	ApproxMembers uint `json:"approximate_members_count,omitempty"`

	Target     *User          `json:"target_user,omitempty"` // partial
	TargetType InviteUserType `json:"target_user_type,omitempty"`

	// Only available if Target is
	ApproxPresences uint `json:"approximate_presence_count,omitempty"`

	InviteMetadata // only available when fetching ChannelInvites or GuildInvites
}

type InviteMetadata added in v0.6.3

type InviteMetadata struct {
	// Number of times this invite has been used
	Uses int `json:"uses"`
	// Max number of times this invite can be used
	MaxUses int `json:"max_uses"`
	// Duration (in seconds) after which the invite expires
	MaxAge Seconds `json:"max_age"`
	// Whether this invite only grants temporary membership
	Temporary bool `json:"temporary"`
	// When this invite was created
	CreatedAt Timestamp `json:"created_at"`
}

Extra information about an invite, will extend the invite object.

type InviteUserType

type InviteUserType uint8
const (
	InviteNormalUser InviteUserType = iota
	InviteUserStream
)

type MFALevel

type MFALevel uint8
const (
	NoMFA MFALevel = iota
	ElevatedMFA
)

type Member

type Member struct {
	User    User        `json:"user"`
	Nick    string      `json:"nick,omitempty"`
	RoleIDs []Snowflake `json:"roles"`

	Joined       Timestamp `json:"joined_at"`
	BoostedSince Timestamp `json:"premium_since,omitempty"`

	Deaf bool `json:"deaf"`
	Mute bool `json:"mute"`
}

func (Member) Mention added in v0.0.11

func (m Member) Mention() string

type Message

type Message struct {
	ID        Snowflake   `json:"id,string"`
	Type      MessageType `json:"type"`
	ChannelID Snowflake   `json:"channel_id,string"`
	GuildID   Snowflake   `json:"guild_id,string,omitempty"`

	// The author object follows the structure of the user object, but is only
	// a valid user in the case where the message is generated by a user or bot
	// user. If the message is generated by a webhook, the author object
	// corresponds to the webhook's id, username, and avatar. You can tell if a
	// message is generated by a webhook by checking for the webhook_id on the
	// message object.
	Author User `json:"author"`

	Content string `json:"content"`

	Timestamp       Timestamp `json:"timestamp,omitempty"`
	EditedTimestamp Timestamp `json:"edited_timestamp,omitempty"`

	TTS    bool `json:"tts"`
	Pinned bool `json:"pinned"`

	// The user objects in the mentions array will only have the partial
	// member field present in MESSAGE_CREATE and MESSAGE_UPDATE events from
	// text-based guild channels.
	Mentions []GuildUser `json:"mentions"`

	MentionRoleIDs  []Snowflake `json:"mention_roles"`
	MentionEveryone bool        `json:"mention_everyone"`

	// Not all channel mentions in a message will appear in mention_channels.
	MentionChannels []ChannelMention `json:"mention_channels,omitempty"`

	Attachments []Attachment `json:"attachments"`
	Embeds      []Embed      `json:"embeds"`

	Reactions []Reaction `json:"reactions,omitempty"`

	// Used for validating a message was sent
	Nonce string `json:"nonce,omitempty"`

	WebhookID   Snowflake           `json:"webhook_id,string,omitempty"`
	Activity    *MessageActivity    `json:"activity,omitempty"`
	Application *MessageApplication `json:"application,omitempty"`
	Reference   *MessageReference   `json:"message_reference,omitempty"`
	Flags       MessageFlags        `json:"flags"`
}

func (Message) URL added in v0.0.11

func (m Message) URL() string

URL generates a Discord client URL to the message. If the message doesn't have a GuildID, it will generate a URL with the guild "@me".

type MessageActivity

type MessageActivity struct {
	Type MessageActivityType `json:"type"`

	// From a Rich Presence event
	PartyID string `json:"party_id,omitempty"`
}

type MessageActivityType

type MessageActivityType uint8
const (
	JoinMessage MessageActivityType = iota + 1
	SpectateMessage
	ListenMessage
	JoinRequestMessage
)

type MessageApplication

type MessageApplication struct {
	ID          Snowflake `json:"id,string"`
	CoverID     string    `json:"cover_image,omitempty"`
	Description string    `json:"description"`
	Icon        string    `json:"icon"`
	Name        string    `json:"name"`
}

type MessageFlags

type MessageFlags enum.Enum
var (
	NullMessage          MessageFlags = enum.Null
	CrosspostedMessage   MessageFlags = 1
	MessageIsCrosspost   MessageFlags = 2
	SuppressEmbeds       MessageFlags = 4
	SourceMessageDeleted MessageFlags = 8
	UrgentMessage        MessageFlags = 16
)

type MessageReference

type MessageReference struct {
	ChannelID Snowflake `json:"channel_id,string"`

	// Field might not be provided
	MessageID Snowflake `json:"message_id,string,omitempty"`
	GuildID   Snowflake `json:"guild_id,string,omitempty"`
}

type MessageType

type MessageType uint8
const (
	DefaultMessage MessageType = iota
	RecipientAddMessage
	RecipientRemoveMessage
	CallMessage
	ChannelNameChangeMessage
	ChannelIconChangeMessage
	ChannelPinnedMessage
	GuildMemberJoinMessage
	NitroBoostMessage
	NitroTier1Message
	NitroTier2Message
	NitroTier3Message
	ChannelFollowAddMessage
	GuildDiscoveryDisqualifiedMessage
	GuildDiscoveryRequalifiedMessage
)

type Milliseconds

type Milliseconds float64

Milliseconds is in float64 because some Discord events return time with a trailing decimal.

func DurationToMilliseconds

func DurationToMilliseconds(dura time.Duration) Milliseconds

func (Milliseconds) Duration

func (ms Milliseconds) Duration() time.Duration

func (Milliseconds) String

func (ms Milliseconds) String() string

type NitroBoost

type NitroBoost uint8
const (
	NoNitroLevel NitroBoost = iota
	NitroLevel1
	NitroLevel2
	NitroLevel3
)

type Notification

type Notification enum.Enum

Notification is the default message notification level of a guild.

var (
	// NullNotification serialized to JSON null.
	// This should only be used on nullable fields.
	NullNotification Notification = enum.Null
	// AllMessages sends notifications for all messages.
	AllMessages Notification = 0
	// OnlyMentions sends notifications only on mention.
	OnlyMentions Notification = 1
)

func (Notification) MarshalJSON added in v0.7.0

func (n Notification) MarshalJSON() ([]byte, error)

func (*Notification) UnmarshalJSON added in v0.7.0

func (n *Notification) UnmarshalJSON(b []byte) error

type Overwrite

type Overwrite struct {
	ID    Snowflake     `json:"id,string,omitempty"`
	Type  OverwriteType `json:"type"`
	Allow Permissions   `json:"allow"`
	Deny  Permissions   `json:"deny"`
}

type OverwriteType

type OverwriteType string
const (
	OverwriteRole   OverwriteType = "role"
	OverwriteMember OverwriteType = "member"
)

type Permissions

type Permissions uint64
var (
	// Allows creation of instant invites
	PermissionCreateInstantInvite Permissions = 1 << 0
	// Allows kicking members
	PermissionKickMembers Permissions = 1 << 1
	// Allows banning members
	PermissionBanMembers Permissions = 1 << 2
	// Allows all permissions and bypasses channel permission overwrites
	PermissionAdministrator Permissions = 1 << 3
	// Allows management and editing of channels
	PermissionManageChannels Permissions = 1 << 4
	// Allows management and editing of the guild
	PermissionManageGuild Permissions = 1 << 5
	// Allows for the addition of reactions to messages
	PermissionAddReactions Permissions = 1 << 6
	// Allows for viewing of audit logs
	PermissionViewAuditLog Permissions = 1 << 7
	// Allows for using priority speaker in a voice channel
	PermissionPrioritySpeaker Permissions = 1 << 8
	// Allows the user to go live
	PermissionStream Permissions = 1 << 9
	// Allows guild members to view a channel, which includes reading messages
	// in text channels
	PermissionViewChannel Permissions = 1 << 10
	// Allows for sending messages in a channel
	PermissionSendMessages Permissions = 1 << 11
	// Allows for sending of /tts messages
	PermissionSendTTSMessages Permissions = 1 << 12
	// Allows for deletion of other users messages
	PermissionManageMessages Permissions = 1 << 13
	// Links sent by users with this permission will be auto-embedded
	PermissionEmbedLinks Permissions = 1 << 14
	// Allows for uploading images and files
	PermissionAttachFiles Permissions = 1 << 15
	// Allows for reading of message history
	PermissionReadMessageHistory Permissions = 1 << 16
	// Allows for using the @everyone tag to notify all users in a channel,
	// and the @here tag to notify all online users in a channel
	PermissionMentionEveryone Permissions = 1 << 17
	// Allows the usage of custom emojis from other servers
	PermissionUseExternalEmojis Permissions = 1 << 18

	// Allows for joining of a voice channel
	PermissionConnect Permissions = 1 << 20
	// Allows for speaking in a voice channel
	PermissionSpeak Permissions = 1 << 21
	// Allows for muting members in a voice channel
	PermissionMuteMembers Permissions = 1 << 22
	// Allows for deafening of members in a voice channel
	PermissionDeafenMembers Permissions = 1 << 23
	// Allows for moving of members between voice channels
	PermissionMoveMembers Permissions = 1 << 24
	// Allows for using voice-activity-detection in a voice channel
	PermissionUseVAD Permissions = 1 << 25
	// Allows for modification of own nickname
	PermissionChangeNickname Permissions = 1 << 26
	// Allows for modification of other users nicknames
	PermissionManageNicknames Permissions = 1 << 27
	// Allows management and editing of roles
	PermissionManageRoles Permissions = 1 << 28
	// Allows management and editing of webhooks
	PermissionManageWebhooks Permissions = 1 << 29
	// Allows management and editing of emojis
	PermissionManageEmojis Permissions = 1 << 30

	PermissionAllText = 0 |
		PermissionViewChannel |
		PermissionSendMessages |
		PermissionSendTTSMessages |
		PermissionManageMessages |
		PermissionEmbedLinks |
		PermissionAttachFiles |
		PermissionReadMessageHistory |
		PermissionMentionEveryone |
		PermissionUseExternalEmojis

	PermissionAllVoice = 0 |
		PermissionConnect |
		PermissionSpeak |
		PermissionMuteMembers |
		PermissionDeafenMembers |
		PermissionMoveMembers |
		PermissionUseVAD |
		PermissionPrioritySpeaker

	PermissionAllChannel = 0 |
		PermissionAllText |
		PermissionAllVoice |
		PermissionCreateInstantInvite |
		PermissionManageRoles |
		PermissionManageChannels |
		PermissionAddReactions |
		PermissionViewAuditLog

	PermissionAll = 0 |
		PermissionAllChannel |
		PermissionKickMembers |
		PermissionBanMembers |
		PermissionManageGuild |
		PermissionAdministrator |
		PermissionManageWebhooks |
		PermissionManageEmojis |
		PermissionManageNicknames |
		PermissionChangeNickname
)

func CalcOverwrites

func CalcOverwrites(guild Guild, channel Channel, member Member) Permissions

func (Permissions) Add

func (p Permissions) Add(perm Permissions) Permissions

func (Permissions) Has

func (p Permissions) Has(perm Permissions) bool

type Presence

type Presence struct {
	User    User        `json:"user"`
	RoleIDs []Snowflake `json:"roles"`

	Nick    string    `json:"nick"`
	GuildID Snowflake `json:"guild_id"`

	PremiumSince Timestamp `json:"premium_since,omitempty"`

	Game       *Activity  `json:"game"`
	Activities []Activity `json:"activities"`

	Status       Status `json:"status"`
	ClientStatus struct {
		Desktop Status `json:"desktop,omitempty"`
		Mobile  Status `json:"mobile,omitempty"`
		Web     Status `json:"web,omitempty"`
	} `json:"client_status"`
}

type Reaction

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

type Role

type Role struct {
	ID   Snowflake `json:"id,string"`
	Name string    `json:"name"`

	Color    Color `json:"color"`
	Hoist    bool  `json:"hoist"` // if the role is separated
	Position int   `json:"position"`

	Permissions Permissions `json:"permissions"`

	Managed     bool `json:"managed"`
	Mentionable bool `json:"mentionable"`
}

func (Role) Mention added in v0.0.11

func (r Role) Mention() string

type Seconds

type Seconds int

func DurationToSeconds

func DurationToSeconds(dura time.Duration) Seconds

func (Seconds) Duration

func (s Seconds) Duration() time.Duration

func (Seconds) MarshalJSON added in v0.7.0

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

func (Seconds) String

func (s Seconds) String() string

type Service

type Service string

Service is used for guild integrations and user connections.

const (
	Twitch  Service = "twitch"
	YouTube Service = "youtube"
)

type Snowflake

type Snowflake int64
const NullSnowflake Snowflake = -1

NullSnowflake gets encoded into a null. This is used for optional and nullable snowflake fields.

func NewSnowflake

func NewSnowflake(t time.Time) Snowflake

func ParseSnowflake added in v0.0.9

func ParseSnowflake(sf string) (Snowflake, error)

func (Snowflake) Increment

func (s Snowflake) Increment() uint16

func (Snowflake) MarshalJSON

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

func (Snowflake) PID

func (s Snowflake) PID() uint8

func (Snowflake) String

func (s Snowflake) String() string

func (Snowflake) Time

func (s Snowflake) Time() time.Time

func (*Snowflake) UnmarshalJSON

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

func (Snowflake) Valid

func (s Snowflake) Valid() bool

func (Snowflake) Worker

func (s Snowflake) Worker() uint8

type Status

type Status string
const (
	UnknownStatus      Status = ""
	OnlineStatus       Status = "online"
	DoNotDisturbStatus Status = "dnd"
	IdleStatus         Status = "idle"
	InvisibleStatus    Status = "invisible"
	OfflineStatus      Status = "offline"
)

type Timestamp

type Timestamp time.Time

Timestamp has a valid zero-value, which can be checked using the Valid() method. This is useful for optional timestamps such as EditedTimestamp.

func NewTimestamp added in v0.0.13

func NewTimestamp(t time.Time) Timestamp

func NowTimestamp added in v0.0.13

func NowTimestamp() Timestamp

func (Timestamp) Format added in v0.0.7

func (t Timestamp) Format(fmt string) string

func (Timestamp) MarshalJSON

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

MarshalJSON returns null if Timestamp is not valid (zero). It returns the time formatted in RFC3339 otherwise.

func (Timestamp) Time added in v0.0.7

func (t Timestamp) Time() time.Time

func (*Timestamp) UnmarshalJSON

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

UnmarshalJSON parses a nullable RFC3339 string into time.

func (Timestamp) Valid added in v0.0.3

func (t Timestamp) Valid() bool

type URL

type URL = string

type UnixMsTimestamp

type UnixMsTimestamp int64

func TimeToMilliseconds added in v0.2.0

func TimeToMilliseconds(t time.Time) UnixMsTimestamp

func (UnixMsTimestamp) String

func (t UnixMsTimestamp) String() string

func (UnixMsTimestamp) Time

func (t UnixMsTimestamp) Time() time.Time

type UnixTimestamp

type UnixTimestamp int64

func (UnixTimestamp) String

func (t UnixTimestamp) String() string

func (UnixTimestamp) Time

func (t UnixTimestamp) Time() time.Time

type User

type User struct {
	ID            Snowflake `json:"id,string"`
	Username      string    `json:"username"`
	Discriminator string    `json:"discriminator"`
	Avatar        Hash      `json:"avatar"`

	Bot bool `json:"bot,omitempty"`
	MFA bool `json:"mfa_enabled,omitempty"`

	DiscordSystem bool `json:"system,omitempty"`
	EmailVerified bool `json:"verified,omitempty"`

	Locale string `json:"locale,omitempty"`
	Email  string `json:"email,omitempty"`

	Flags       UserFlags `json:"flags,omitempty"`
	PublicFlags UserFlags `json:"public_flags,omitempty"`
	Nitro       UserNitro `json:"premium_type,omitempty"`
}

func (User) AvatarURL added in v0.0.11

func (u User) AvatarURL() string

func (User) Mention added in v0.0.11

func (u User) Mention() string

type UserFlags

type UserFlags uint32
const (
	DiscordEmployee UserFlags = 1 << iota
	DiscordPartner
	HypeSquadEvents
	BugHunterLvl1

	HouseBravery
	HouseBrilliance
	HouseBalance
	EarlySupporter
	TeamUser

	System

	BugHunterLvl2

	VerifiedBot
	VerifiedBotDeveloper
)
const NoFlag UserFlags = 0

type UserNitro

type UserNitro uint8
const (
	NoUserNitro UserNitro = iota
	NitroClassic
	NitroFull
)

type Verification

type Verification enum.Enum

Verification is the verification level required for a guild.

var (
	// NullVerification serialized to JSON null.
	// This should only be used on nullable fields.
	NullVerification Verification = enum.Null
	// NoVerification required no verification.
	NoVerification Verification = 0
	// LowVerification requires a verified email
	LowVerification Verification = 1
	// MediumVerification requires the user be registered for at least 5
	// minutes.
	MediumVerification Verification = 2
	// HighVerification requires the member be in the server for more than 10
	// minutes.
	HighVerification Verification = 3
	// VeryHighVerification requires the member to have a verified phone
	// number.
	VeryHighVerification Verification = 4
)

func (Verification) MarshalJSON added in v0.7.0

func (v Verification) MarshalJSON() ([]byte, error)

func (*Verification) UnmarshalJSON added in v0.7.0

func (v *Verification) UnmarshalJSON(b []byte) error

type VoiceRegion

type VoiceRegion struct {
	ID         string `json:"id"`
	Name       string `json:"name"`
	VIP        bool   `json:"vip"`
	Optimal    bool   `json:"optimal"`
	Deprecated bool   `json:"deprecated"`
	Custom     bool   `json:"custom"` // used for events
}

type VoiceState

type VoiceState struct {
	// GuildID isn't available from the Guild struct.
	GuildID Snowflake `json:"guild_id,string"`

	ChannelID Snowflake `json:"channel_id,string"`
	UserID    Snowflake `json:"user_id,string"`
	Member    *Member   `json:"member,omitempty"`
	SessionID string    `json:"session_id"`

	Deaf bool `json:"deaf"`
	Mute bool `json:"mute"`

	SelfDeaf   bool `json:"self_deaf"`
	SelfMute   bool `json:"self_mute"`
	SelfStream bool `json:"self_stream,omitempty"`
	Suppress   bool `json:"suppress"`
}

type Webhook

type Webhook struct {
	ID   Snowflake   `json:"id"`
	Type WebhookType `json:"type"`
	User User        `json:"user"` // creator

	GuildID   Snowflake `json:"guild_id,omitempty"`
	ChannelID Snowflake `json:"channel_id"`

	Name   string `json:"name"`
	Avatar Hash   `json:"avatar"`
	Token  string `json:"token"` // incoming webhooks only
}

type WebhookType

type WebhookType uint8
const (
	IncomingWebhook WebhookType
	ChannelFollowerWebhook
)

Jump to

Keyboard shortcuts

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