discord

package
v0.6.2 Latest Latest
Warning

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

Go to latest
Published: May 6, 2020 License: ISC Imports: 5 Imported by: 39

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. Seriously. The fucker who thought of this API thought it was also a good idea to return "null" instead of "5000." What the fucK? It has the same byte count, thus the same size. Sending the number over means it could be changed anytime and not force the developers to recheck. You could make the change right today and it would just work on all the clients. But no. IT'S FUCKING NULL!

View Source
const DiscordEpoch = 1420070400000 * int64(time.Millisecond)
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 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.

func TimeToDiscordEpoch

func TimeToDiscordEpoch(t time.Time) int64

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 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 ChannelType

type ChannelType uint8
const (
	GuildText ChannelType = iota
	DirectMessage
	GuildVoice
	GroupDM
	GuildCategory
	GuildNews
	GuildStore
)

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 ExplicitFilter

type ExplicitFilter uint8
const (
	NoContentFilter ExplicitFilter = iota
	MembersWithoutRoles
	AllMembers
)

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"`
}

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    int `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

	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"`
}

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 uint32
const (
	CrosspostedMessage MessageFlags = 1 << iota
	MessageIsCrosspost
	SuppressEmbeds
	SourceMessageDeleted
	UrgentMessage
)

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 uint8
const (
	AllMessages Notification = iota
	OnlyMentions
)

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
const (
	// Allows creation of instant invites
	PermissionCreateInstantInvite Permissions = 1 << iota
	// Allows kicking members
	PermissionKickMembers
	// Allows banning members
	PermissionBanMembers
	// Allows all permissions and bypasses channel permission overwrites
	PermissionAdministrator
	// Allows management and editing of channels
	PermissionManageChannels
	// Allows management and editing of the guild
	PermissionManageGuild
	// Allows for the addition of reactions to messages
	PermissionAddReactions
	// Allows for viewing of audit logs
	PermissionViewAuditLog
	// Allows for using priority speaker in a voice channel
	PermissionPrioritySpeaker
	// Allows the user to go live
	PermissionStream
	// Allows guild members to view a channel, which includes reading messages
	// in text channels
	PermissionViewChannel
	// Allows for sending messages in a channel
	PermissionSendMessages
	// Allows for sending of /tts messages
	PermissionSendTTSMessages
	// Allows for deletion of other users messages
	PermissionManageMessages
	// Links sent by users with this permission will be auto-embedded
	PermissionEmbedLinks
	// Allows for uploading images and files
	PermissionAttachFiles
	// Allows for reading of message history
	PermissionReadMessageHistory
	// 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
	// Allows the usage of custom emojis from other servers
	PermissionUseExternalEmojis

	// Allows for joining of a voice channel
	PermissionConnect
	// Allows for speaking in a voice channel
	PermissionSpeak
	// Allows for muting members in a voice channel
	PermissionMuteMembers
	// Allows for deafening of members in a voice channel
	PermissionDeafenMembers
	// Allows for moving of members between voice channels
	PermissionMoveMembers
	// Allows for using voice-activity-detection in a voice channel
	PermissionUseVAD
	// Allows for modification of own nickname
	PermissionChangeNickname
	// Allows for modification of other users nicknames
	PermissionManageNicknames
	// Allows management and editing of roles
	PermissionManageRoles
	// Allows management and editing of webhooks
	PermissionManageWebhooks
	// Allows management and editing of emojis
	PermissionManageEmojis

	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) 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

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 uint8
const (
	NoVerification Verification = iota
	// LowVerification requires a verified email
	LowVerification
	// MediumVerification requires the user be registered for at least 5
	// minutes.
	MediumVerification
	// HighVerification requires the member be in the server for more than 10
	// minutes.
	HighVerification
	// VeryHighVerification requires the member to have a verified phone
	// number.
	VeryHighVerification
)

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