discordgo

package module
v0.20.43 Latest Latest
Warning

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

Go to latest
Published: Feb 2, 2020 License: BSD-3-Clause Imports: 31 Imported by: 1

README

DiscordGo

GoDoc Go report Build Status Discord Gophers Discord API

DiscordGo is a Go package that provides low level bindings to the Discord chat client API. DiscordGo has nearly complete support for all of the Discord API endpoints, websocket interface, and voice interface.

If you would like to help the DiscordGo package please use this link to add the official DiscordGo test bot dgo to your server. This provides indispensable help to this project.

  • See dgVoice package for an example of additional voice helper functions and features for DiscordGo.

  • See dca for an experimental stand alone tool that wraps ffmpeg to create opus encoded audio appropriate for use with Discord (and DiscordGo).

For help with this package or general Go discussion, please join the Discord Gophers chat server.

Getting Started

master vs develop Branch
  • The master branch represents the latest released version of DiscordGo. This branch will always have a stable and tested version of the library. Each release is tagged and you can easily download a specific release and view release notes on the github releases page.

  • The develop branch is where all development happens and almost always has new features over the master branch. However breaking changes are frequently added to develop and even sometimes bugs are introduced. Bugs get fixed and the breaking changes get documented before pushing to master.

So, what should you use?

If you can accept the constant changing nature of develop, it is the recommended branch to use. Otherwise, if you want to tail behind development slightly and have a more stable package with documented releases, use master.

Installing

This assumes you already have a working Go environment, if not please see this page first.

go get will always pull the latest released version from the master branch.

go get github.com/bwmarrin/discordgo

If you want to use the develop branch, follow these steps next.

cd $GOPATH/src/github.com/bwmarrin/discordgo
git checkout develop
Usage

Import the package into your project.

import "github.com/bwmarrin/discordgo"

Construct a new Discord client which can be used to access the variety of Discord API functions and to set callback functions for Discord events.

discord, err := discordgo.New("Bot " + "authentication token")

See Documentation and Examples below for more detailed information.

Documentation

NOTICE : This library and the Discord API are unfinished. Because of that there may be major changes to library in the future.

The DiscordGo code is fairly well documented at this point and is currently the only documentation available. Both GoDoc and GoWalker (below) present that information in a nice format.

  • GoDoc
  • Go Walker
  • Hand crafted documentation coming eventually.

Examples

Below is a list of examples and other projects using DiscordGo. Please submit an issue if you would like your project added or removed from this list.

Troubleshooting

For help with common problems please reference the Troubleshooting section of the project wiki.

Contributing

Contributions are very welcomed, however please follow the below guidelines.

  • First open an issue describing the bug or enhancement so it can be discussed.
  • Fork the develop branch and make your changes.
  • Try to match current naming conventions as closely as possible.
  • This package is intended to be a low level direct mapping of the Discord API, so please avoid adding enhancements outside of that scope without first discussing it.
  • Create a Pull Request with your changes against the develop branch.

List of Discord APIs

See this chart for a feature comparison and list of other Discord API libraries.

Special Thanks

Chris Rhodes - For the DiscordGo logo and tons of PRs.

Documentation

Overview

Package discordgo provides Discord binding for Go

Index

Constants

View Source
const (
	AuditLogActionGuildUpdate = 1

	AuditLogActionChannelCreate          = 10
	AuditLogActionChannelUpdate          = 11
	AuditLogActionChannelDelete          = 12
	AuditLogActionChannelOverwriteCreate = 13
	AuditLogActionChannelOverwriteUpdate = 14
	AuditLogActionChannelOverwriteDelete = 15

	AuditLogActionMemberKick       = 20
	AuditLogActionMemberPrune      = 21
	AuditLogActionMemberBanAdd     = 22
	AuditLogActionMemberBanRemove  = 23
	AuditLogActionMemberUpdate     = 24
	AuditLogActionMemberRoleUpdate = 25
	AuditLogActionMemberMove       = 26
	AuditLogActionMemberDisconnect = 27
	AuditLogActionBotAdd           = 28

	AuditLogActionRoleCreate = 30
	AuditLogActionRoleUpdate = 31
	AuditLogActionRoleDelete = 32

	AuditLogActionInviteCreate = 40
	AuditLogActionInviteUpdate = 41
	AuditLogActionInviteDelete = 42

	AuditLogActionWebhookCreate = 50
	AuditLogActionWebhookUpdate = 51
	AuditLogActionWebhookDelete = 52

	AuditLogActionEmojiCreate = 60
	AuditLogActionEmojiUpdate = 61
	AuditLogActionEmojiDelete = 62

	AuditLogActionMessageDelete     = 72
	AuditLogActionMessageBulkDelete = 73
	AuditLogActionMessagePin        = 74
	AuditLogActionMessageUnPin      = 75

	AuditLogActionIntegrationCreate = 80
	AuditLogActionIntegrationUpdate = 81
	AuditLogActionIntegrationDelete = 82
)

Block contains Discord Audit Log Action Types

View Source
const (
	ColorGreen     = Color(0x2ecc71)
	ColorBlue      = Color(0x3498db)
	ColorPurple    = Color(0x9b59b6)
	ColorGold      = Color(0xf1c40f)
	ColorRed       = Color(0xe74c3c)
	ColorOrange    = Color(0xe67e22)
	ColorMagenta   = Color(0xe91e63)
	ColorTeal      = Color(0x1abc9c)
	ColorLightGrey = Color(0x979c9f)
	ColorDarkGrey  = Color(0x607d8b)
	ColorBlurple   = Color(0x7289da)
	ColorGreyple   = Color(0x99aab5)
)

These Colors are constants to be used for easily using base colors

View Source
const (

	// LogError level is used for critical errors that could lead to data loss
	// or panic that would not be returned to a calling function.
	LogError int = iota

	// LogWarning level is used for very abnormal events and errors that are
	// also returned to a calling function.
	LogWarning

	// LogInformational level is used for normal non-error activity
	LogInformational

	// LogDebug level is for very detailed non-error activity.  This is
	// very spammy and will impact performance.
	LogDebug
)
View Source
const (
	PermissionReadMessages = PermissionOffset(1 << (iota + 10))
	PermissionSendMessages
	PermissionSendTTSMessages
	PermissionManageMessages
	PermissionEmbedLinks
	PermissionAttachFiles
	PermissionReadMessageHistory
	PermissionMentionEveryone
	PermissionUseExternalEmojis
)

Constants for the different bit offsets of text channel permissions

View Source
const (
	PermissionVoiceConnect = PermissionOffset(1 << (iota + 20))
	PermissionVoiceSpeak
	PermissionVoiceMuteMembers
	PermissionVoiceDeafenMembers
	PermissionVoiceMoveMembers
	PermissionVoiceUseVAD
	PermissionVoicePrioritySpeaker = 1 << (iota + 2)
	PermissionVoiceStream
)

Constants for the different bit offsets of voice permissions

View Source
const (
	PermissionChangeNickname = PermissionOffset(1 << (iota + 26))
	PermissionManageNicknames
	PermissionManageRoles
	PermissionManageWebhooks
	PermissionManageEmojis
)

Constants for general management.

View Source
const (
	PermissionCreateInstantInvite = PermissionOffset(1 << iota)
	PermissionKickMembers
	PermissionBanMembers
	PermissionAdministrator
	PermissionManageChannels
	PermissionManageServer
	PermissionAddReactions
	PermissionViewAuditLogs
)

Constants for the different bit offsets of general permissions

View Source
const (
	ErrCodeUnknownAccount     = 10001
	ErrCodeUnknownApplication = 10002
	ErrCodeUnknownChannel     = 10003
	ErrCodeUnknownGuild       = 10004
	ErrCodeUnknownIntegration = 10005
	ErrCodeUnknownInvite      = 10006
	ErrCodeUnknownMember      = 10007
	ErrCodeUnknownMessage     = 10008
	ErrCodeUnknownOverwrite   = 10009
	ErrCodeUnknownProvider    = 10010
	ErrCodeUnknownRole        = 10011
	ErrCodeUnknownToken       = 10012
	ErrCodeUnknownUser        = 10013
	ErrCodeUnknownEmoji       = 10014
	ErrCodeUnknownWebhook     = 10015

	ErrCodeBotsCannotUseEndpoint  = 20001
	ErrCodeOnlyBotsCanUseEndpoint = 20002

	ErrCodeMaximumGuildsReached     = 30001
	ErrCodeMaximumFriendsReached    = 30002
	ErrCodeMaximumPinsReached       = 30003
	ErrCodeMaximumGuildRolesReached = 30005
	ErrCodeTooManyReactions         = 30010

	ErrCodeUnauthorized = 40001

	ErrCodeMissingAccess                             = 50001
	ErrCodeInvalidAccountType                        = 50002
	ErrCodeCannotExecuteActionOnDMChannel            = 50003
	ErrCodeEmbedDisabled                             = 50004
	ErrCodeCannotEditFromAnotherUser                 = 50005
	ErrCodeCannotSendEmptyMessage                    = 50006
	ErrCodeCannotSendMessagesToThisUser              = 50007
	ErrCodeCannotSendMessagesInVoiceChannel          = 50008
	ErrCodeChannelVerificationLevelTooHigh           = 50009
	ErrCodeOAuth2ApplicationDoesNotHaveBot           = 50010
	ErrCodeOAuth2ApplicationLimitReached             = 50011
	ErrCodeInvalidOAuthState                         = 50012
	ErrCodeMissingPermissions                        = 50013
	ErrCodeInvalidAuthenticationToken                = 50014
	ErrCodeNoteTooLong                               = 50015
	ErrCodeTooFewOrTooManyMessagesToDelete           = 50016
	ErrCodeCanOnlyPinMessageToOriginatingChannel     = 50019
	ErrCodeCannotExecuteActionOnSystemMessage        = 50021
	ErrCodeMessageProvidedTooOldForBulkDelete        = 50034
	ErrCodeInvalidFormBody                           = 50035
	ErrCodeInviteAcceptedToGuildApplicationsBotNotIn = 50036

	ErrCodeReactionBlocked = 90001
)

Block contains Discord JSON Error Response codes

View Source
const FailedHeartbeatAcks time.Duration = 5 * time.Millisecond

FailedHeartbeatAcks is the Number of heartbeat intervals to wait until forcing a connection restart.

View Source
const VERSION = "0.20.1"

VERSION of DiscordGo, follows Semantic Versioning. (http://semver.org/)

Variables

View Source
var (
	EndpointStatus     = "https://status.discordapp.com/api/v2/"
	EndpointSm         = EndpointStatus + "scheduled-maintenances/"
	EndpointSmActive   = EndpointSm + "active.json"
	EndpointSmUpcoming = EndpointSm + "upcoming.json"

	EndpointDiscord    = "https://discordapp.com/"
	EndpointAPI        = EndpointDiscord + "api/v" + APIVersion + "/"
	EndpointGuilds     = EndpointAPI + "guilds/"
	EndpointChannels   = EndpointAPI + "channels/"
	EndpointUsers      = EndpointAPI + "users/"
	EndpointGateway    = EndpointAPI + "gateway"
	EndpointGatewayBot = EndpointGateway + "/bot"
	EndpointWebhooks   = EndpointAPI + "webhooks/"

	EndpointCDN             = "https://cdn.discordapp.com/"
	EndpointCDNAttachments  = EndpointCDN + "attachments/"
	EndpointCDNAvatars      = EndpointCDN + "avatars/"
	EndpointCDNIcons        = EndpointCDN + "icons/"
	EndpointCDNSplashes     = EndpointCDN + "splashes/"
	EndpointCDNChannelIcons = EndpointCDN + "channel-icons/"
	EndpointCDNBanners      = EndpointCDN + "banners/"

	EndpointAuth           = EndpointAPI + "auth/"
	EndpointLogin          = EndpointAuth + "login"
	EndpointLogout         = EndpointAuth + "logout"
	EndpointVerify         = EndpointAuth + "verify"
	EndpointVerifyResend   = EndpointAuth + "verify/resend"
	EndpointForgotPassword = EndpointAuth + "forgot"
	EndpointResetPassword  = EndpointAuth + "reset"
	EndpointRegister       = EndpointAuth + "register"

	EndpointVoice        = EndpointAPI + "/voice/"
	EndpointVoiceRegions = EndpointVoice + "regions"
	EndpointVoiceIce     = EndpointVoice + "ice"

	EndpointTutorial           = EndpointAPI + "tutorial/"
	EndpointTutorialIndicators = EndpointTutorial + "indicators"

	EndpointTrack        = EndpointAPI + "track"
	EndpointSso          = EndpointAPI + "sso"
	EndpointReport       = EndpointAPI + "report"
	EndpointIntegrations = EndpointAPI + "integrations"

	EndpointUser               = func(uID string) string { return EndpointUsers + uID }
	EndpointUserAvatar         = func(uID, aID string) string { return EndpointCDNAvatars + uID + "/" + aID + ".png" }
	EndpointUserAvatarAnimated = func(uID, aID string) string { return EndpointCDNAvatars + uID + "/" + aID + ".gif" }
	EndpointDefaultUserAvatar  = func(uDiscriminator string) string {
		uDiscriminatorInt, _ := strconv.Atoi(uDiscriminator)
		return EndpointCDN + "embed/avatars/" + strconv.Itoa(uDiscriminatorInt%5) + ".png"
	}
	EndpointUserSettings      = func(uID string) string { return EndpointUsers + uID + "/settings" }
	EndpointUserGuilds        = func(uID string) string { return EndpointUsers + uID + "/guilds" }
	EndpointUserGuild         = func(uID, gID string) string { return EndpointUsers + uID + "/guilds/" + gID }
	EndpointUserGuildSettings = func(uID, gID string) string { return EndpointUsers + uID + "/guilds/" + gID + "/settings" }
	EndpointUserChannels      = func(uID string) string { return EndpointUsers + uID + "/channels" }
	EndpointUserDevices       = func(uID string) string { return EndpointUsers + uID + "/devices" }
	EndpointUserConnections   = func(uID string) string { return EndpointUsers + uID + "/connections" }
	EndpointUserNotes         = func(uID string) string { return EndpointUsers + "@me/notes/" + uID }

	EndpointGuild                = func(gID string) string { return EndpointGuilds + gID }
	EndpointGuildChannels        = func(gID string) string { return EndpointGuilds + gID + "/channels" }
	EndpointGuildMembers         = func(gID string) string { return EndpointGuilds + gID + "/members" }
	EndpointGuildMember          = func(gID, uID string) string { return EndpointGuilds + gID + "/members/" + uID }
	EndpointGuildMemberRole      = func(gID, uID, rID string) string { return EndpointGuilds + gID + "/members/" + uID + "/roles/" + rID }
	EndpointGuildBans            = func(gID string) string { return EndpointGuilds + gID + "/bans" }
	EndpointGuildBan             = func(gID, uID string) string { return EndpointGuilds + gID + "/bans/" + uID }
	EndpointGuildIntegrations    = func(gID string) string { return EndpointGuilds + gID + "/integrations" }
	EndpointGuildIntegration     = func(gID, iID string) string { return EndpointGuilds + gID + "/integrations/" + iID }
	EndpointGuildIntegrationSync = func(gID, iID string) string { return EndpointGuilds + gID + "/integrations/" + iID + "/sync" }
	EndpointGuildRoles           = func(gID string) string { return EndpointGuilds + gID + "/roles" }
	EndpointGuildRole            = func(gID, rID string) string { return EndpointGuilds + gID + "/roles/" + rID }
	EndpointGuildInvites         = func(gID string) string { return EndpointGuilds + gID + "/invites" }
	EndpointGuildEmbed           = func(gID string) string { return EndpointGuilds + gID + "/embed" }
	EndpointGuildPrune           = func(gID string) string { return EndpointGuilds + gID + "/prune" }
	EndpointGuildIcon            = func(gID, hash string) string { return EndpointCDNIcons + gID + "/" + hash + ".png" }
	EndpointGuildIconAnimated    = func(gID, hash string) string { return EndpointCDNIcons + gID + "/" + hash + ".gif" }
	EndpointGuildSplash          = func(gID, hash string) string { return EndpointCDNSplashes + gID + "/" + hash + ".png" }
	EndpointGuildWebhooks        = func(gID string) string { return EndpointGuilds + gID + "/webhooks" }
	EndpointGuildAuditLogs       = func(gID string) string { return EndpointGuilds + gID + "/audit-logs" }
	EndpointGuildEmojis          = func(gID string) string { return EndpointGuilds + gID + "/emojis" }
	EndpointGuildEmoji           = func(gID, eID string) string { return EndpointGuilds + gID + "/emojis/" + eID }
	EndpointGuildBanner          = func(gID, hash string) string { return EndpointCDNBanners + gID + "/" + hash + ".png" }

	EndpointChannel                   = func(cID string) string { return EndpointChannels + cID }
	EndpointChannelPermissions        = func(cID string) string { return EndpointChannels + cID + "/permissions" }
	EndpointChannelPermission         = func(cID, tID string) string { return EndpointChannels + cID + "/permissions/" + tID }
	EndpointChannelInvites            = func(cID string) string { return EndpointChannels + cID + "/invites" }
	EndpointChannelTyping             = func(cID string) string { return EndpointChannels + cID + "/typing" }
	EndpointChannelMessages           = func(cID string) string { return EndpointChannels + cID + "/messages" }
	EndpointChannelMessage            = func(cID, mID string) string { return EndpointChannels + cID + "/messages/" + mID }
	EndpointChannelMessageAck         = func(cID, mID string) string { return EndpointChannels + cID + "/messages/" + mID + "/ack" }
	EndpointChannelMessagesBulkDelete = func(cID string) string { return EndpointChannel(cID) + "/messages/bulk-delete" }
	EndpointChannelMessagesPins       = func(cID string) string { return EndpointChannel(cID) + "/pins" }
	EndpointChannelMessagePin         = func(cID, mID string) string { return EndpointChannel(cID) + "/pins/" + mID }

	EndpointGroupIcon = func(cID, hash string) string { return EndpointCDNChannelIcons + cID + "/" + hash + ".png" }

	EndpointChannelWebhooks = func(cID string) string { return EndpointChannel(cID) + "/webhooks" }
	EndpointWebhook         = func(wID string) string { return EndpointWebhooks + wID }
	EndpointWebhookToken    = func(wID, token string) string { return EndpointWebhooks + wID + "/" + token }

	EndpointMessageReactionsAll = func(cID, mID string) string {
		return EndpointChannelMessage(cID, mID) + "/reactions"
	}
	EndpointMessageReactions = func(cID, mID, eID string) string {
		return EndpointChannelMessage(cID, mID) + "/reactions/" + eID
	}
	EndpointMessageReaction = func(cID, mID, eID, uID string) string {
		return EndpointMessageReactions(cID, mID, eID) + "/" + uID
	}

	EndpointRelationships       = func() string { return EndpointUsers + "@me" + "/relationships" }
	EndpointRelationship        = func(uID string) string { return EndpointRelationships() + "/" + uID }
	EndpointRelationshipsMutual = func(uID string) string { return EndpointUsers + uID + "/relationships" }

	EndpointGuildCreate = EndpointAPI + "guilds"

	EndpointInvite = func(iID string) string { return EndpointAPI + "invite/" + iID }

	EndpointIntegrationsJoin = func(iID string) string { return EndpointAPI + "integrations/" + iID + "/join" }

	EndpointEmoji         = func(eID string) string { return EndpointAPI + "emojis/" + eID + ".png" }
	EndpointEmojiAnimated = func(eID string) string { return EndpointAPI + "emojis/" + eID + ".gif" }

	EndpointOauth2            = EndpointAPI + "oauth2/"
	EndpointApplications      = EndpointOauth2 + "applications"
	EndpointApplication       = func(aID string) string { return EndpointApplications + "/" + aID }
	EndpointApplicationsBot   = func(aID string) string { return EndpointApplications + "/" + aID + "/bot" }
	EndpointApplicationAssets = func(aID string) string { return EndpointApplications + "/" + aID + "/assets" }
)

Known Discord API Endpoints.

View Source
var (
	// ErrNotATextChannel gets returned when a method gets called on a channel
	// that does not support sending messages to them.
	ErrNotATextChannel = errors.New("not a text or dm channel")

	// ErrNotAVoiceChannel gets returned when a method gets called on a channel
	// that is not a Guild Voice channel but does need to be for the method to work.
	ErrNotAVoiceChannel = errors.New("not a voice channel")

	// ErrNotAGuildChannel gets returned when a method gets called on a channel
	// that is not inside of a Guild but does need to be for the method to work.
	ErrNotAGuildChannel = errors.New("not a channel in a guild")

	// ErrNotOverwriteSettable gets returned when an IDGettable that isn't an user, member or role,
	// gets passed to a function to set or request the permission overwrite for
	ErrNotOverwriteSettable = errors.New("target parameter must be either a user, member or a role")

	// ErrObjectNotFound gets returned when the requested object wasn't found
	ErrObjectNotFound = errors.New("requested object not found")

	// ErrNilState is returned when the state is nil.
	ErrNilState = errors.New("state not instantiated, please use discordgo.New() or assign Session.State")

	// ErrStateNotFound is returned when the state cache
	// requested is not found
	ErrStateNotFound = errors.New("state cache not found")

	// ErrRolePositionBounds gets returned when trying to set the role position to lower than 1
	ErrRolePositionBounds = errors.New("the position cannot be lower than 1")

	// ErrUnmovableDefaultRole gets returned when trying to move the default role as this is impossible
	ErrUnmovableDefaultRole = errors.New("can't move the default role")

	// ErrWSAlreadyOpen is returned when you attempt to open
	// a websocket that already is open.
	ErrWSAlreadyOpen = errors.New("web socket already opened")

	// ErrWSNotFound is returned when you attempt to use a websocket
	// that doesn't exist
	ErrWSNotFound = errors.New("no websocket connection exists")

	// ErrWSShardBounds is returned when you try to use a shard ID that is
	// less than the total shard count
	ErrWSShardBounds = errors.New("ShardID must be less than ShardCount")

	// ErrNotACustomEmoji gets returned when a method gets called on an unicode emoji
	// that can only be called on custom emojis
	ErrNotACustomEmoji = errors.New("you can't do this to a custom emoji")

	// ErrUnknownEmojiGuild gets returned when the method requires the emoji to be from
	// a guild that is cached, but it isn't
	ErrUnknownEmojiGuild = errors.New("the guild that this emoji comes from is not in the cache")

	// ErrJSONUnmarshal gets returned when the JSON unmarshall fails
	ErrJSONUnmarshal = errors.New("json unmarshal")

	// ErrStatusOffline gets returned when trying to set your status to offline
	ErrStatusOffline = errors.New("you can't set your Status to offline")

	// ErrVerificationLevelBounds gets returned when trying to set a verification level that is not between 0 and 3
	ErrVerificationLevelBounds = errors.New("VerificationLevel out of bounds, should be between 0 and 3")

	// ErrPruneDaysBounds gets returned when a prune gets requested of less than 1 day
	ErrPruneDaysBounds = errors.New("the number of days should be more than or equal to 1")

	// ErrGuildNoIcon gets returned when the guild does not have a icon set while requesting the icon image
	ErrGuildNoIcon = errors.New("guild does not have an icon set")

	// ErrGuildNoSplash gets returned when the guild does not have a splash set while requesting the splash image
	ErrGuildNoSplash = errors.New("guild does not have a splash set")

	// ErrUnauthorized gets returned when the HTTP request was unauthorized
	ErrUnauthorized = errors.New("HTTP request was unauthorized. This could be because the provided token was not a bot token")
)
View Source
var APIVersion = "6"

APIVersion is the Discord API version used for the REST and Websocket API.

View Source
var Logger func(msgL, caller int, format string, a ...interface{})

Logger can be used to replace the standard logging for discordgo

Functions

func Contains added in v0.20.0

func Contains(haystack []string, needle string) bool

Contains checks if a slice of strings contains the string to search for haystack : slice of strings to search in needle : string to search for

func ContainsIDObject added in v0.20.0

func ContainsIDObject(haystack []IDGettable, needle IDGettable) (contains bool)

ContainsIDObject checks if the haystack IDGettable contains the needle IDGettable haystack : slice of IDGettables to search in needle : IDGettable to search for

func SnowflakeToTime added in v0.20.0

func SnowflakeToTime(snowflake string) (returnTime time.Time, err error)

SnowflakeToTime converts a snowflake ID to a Time object snowflake : the snowflake ID to convert

Types

type APIErrorMessage added in v0.15.0

type APIErrorMessage struct {
	Code    int    `json:"code"`
	Message string `json:"message"`
}

An APIErrorMessage is an api error message returned from discord

type Ack added in v0.15.0

type Ack struct {
	Token string `json:"token"`
}

An Ack is used to ack messages

type Application added in v0.12.0

type Application struct {
	ID                  string    `json:"id,omitempty"`
	Name                string    `json:"name"`
	Description         string    `json:"description,omitempty"`
	Icon                string    `json:"icon,omitempty"`
	Secret              string    `json:"secret,omitempty"`
	RedirectURIs        *[]string `json:"redirect_uris,omitempty"`
	BotRequireCodeGrant bool      `json:"bot_require_code_grant,omitempty"`
	BotPublic           bool      `json:"bot_public,omitempty"`
	RPCApplicationState int       `json:"rpc_application_state,omitempty"`
	Flags               int       `json:"flags,omitempty"`
	Owner               *User     `json:"owner"`
	Bot                 *User     `json:"bot"`
}

An Application struct stores values for a Discord OAuth2 Application

type Asset added in v0.20.31

type Asset struct {
	Type int    `json:"type"`
	ID   string `json:"id"`
	Name string `json:"name"`
}

Asset struct stores values for an asset of an application

type Assets added in v0.18.0

type Assets struct {
	LargeImageID string `json:"large_image,omitempty"`
	SmallImageID string `json:"small_image,omitempty"`
	LargeText    string `json:"large_text,omitempty"`
	SmallText    string `json:"small_text,omitempty"`
}

An Assets struct contains assets and labels used in the rich presence "playing .." Game

type AuditLogChanges added in v0.20.10

type AuditLogChanges struct {
	VerificationLevel           VerificationLevel
	ExplicitContentFilterLevel  ExplicitContentFilterLevel
	Allow                       Permissions
	Deny                        Permissions
	Permissions                 Permissions
	ID                          string
	Color                       Color
	Owner                       *User
	Inviter                     *User
	Channel                     *Channel
	AFKChannel                  *Channel
	WidgetChannel               *Channel
	PermissionOverwrites        []*PermissionOverwrite
	Splash                      string
	Icon                        string
	Avatar                      string
	RateLimitPerUser            int
	DefaultMessageNotifications int
	GuildName                   string
	GuildRegion                 string
	AFKTimeout                  int
	MfaLevel                    MfaLevel
	VanityURL                   string
	PruneDeleteDays             int
	WidgetEnabled               bool
	Position                    int
	Topic                       string
	Bitrate                     int
	NSFW                        bool
	ApplicationID               string
	Hoist                       bool
	Mentionable                 bool
	InviteCode                  string
	MaxUses                     int
	Uses                        int
	MaxAge                      int
	Temporary                   bool
	Deaf                        bool
	Mute                        bool
	Nickname                    string
	Type                        string
	RolesAdded                  []*Role
	RolesRemoved                []*Role
}

AuditLogChanges contains the data before or after the change occurred that made the audit log entry Most data will not be filled all the time and you should always be aware of what is being changed before accessing this object

type AuditLogEntry added in v0.20.9

type AuditLogEntry struct {
	TargetID   string `json:"target_id"`
	RawChanges []struct {
		NewValue interface{} `json:"new_value"`
		OldValue interface{} `json:"old_value"`
		Key      string      `json:"key"`
	} `json:"changes,omitempty"`
	UserID     string `json:"user_id"`
	ID         string `json:"id"`
	ActionType int    `json:"action_type"`
	Options    struct {
		DeleteMembersDay string `json:"delete_member_days"`
		MembersRemoved   string `json:"members_removed"`
		ChannelID        string `json:"channel_id"`
		Count            string `json:"count"`
		ID               string `json:"id"`
		Type             string `json:"type"`
		RoleName         string `json:"role_name"`
	} `json:"options,omitempty"`
	Reason  string   `json:"reason"`
	Session *Session `json:"-"`
	GuildID string   `json:"-"`
}

AuditLogEntry describes an entry in the guild audit log

func (*AuditLogEntry) Changes added in v0.20.9

func (e *AuditLogEntry) Changes() (before, after *AuditLogChanges)

Changes returns a before and after AuditLogChanges for the changes in the AuditLogEntry

func (AuditLogEntry) CreatedAt added in v0.20.10

func (e AuditLogEntry) CreatedAt() (creation time.Time, err error)

CreatedAt returns the audit log entry's creation time

func (AuditLogEntry) GetID added in v0.20.10

func (e AuditLogEntry) GetID() string

GetID returns the audit log entry's ID

type Bucket added in v0.15.0

type Bucket struct {
	sync.Mutex
	Key       string
	Remaining int

	Userdata interface{}
	// contains filtered or unexported fields
}

Bucket represents a ratelimit bucket, each bucket gets ratelimited individually (-global ratelimits)

func (*Bucket) Release added in v0.15.0

func (b *Bucket) Release(headers http.Header) error

Release unlocks the bucket and reads the headers to update the buckets ratelimit info and locks up the whole thing in case if there's a global ratelimit.

type Channel

type Channel struct {
	// The ID of the channel.
	ID string `json:"id"`

	// The ID of the guild to which the channel belongs, if it is in a guild.
	// Else, this ID is empty (e.g. DM channels).
	GuildID string `json:"guild_id"`

	// The name of the channel.
	Name string `json:"name"`

	// The topic of the channel.
	Topic string `json:"topic"`

	// The type of the channel.
	Type ChannelType `json:"type"`

	// The ID of the last message sent in the channel. This is not
	// guaranteed to be an ID of a valid message.
	LastMessageID string `json:"last_message_id"`

	// The timestamp of the last pinned message in the channel.
	// Empty if the channel has no pinned messages.
	LastPinTimestamp Timestamp `json:"last_pin_timestamp"`

	// Whether the channel is marked as NSFW.
	NSFW bool `json:"nsfw"`

	// Icon of the group DM channel.
	Icon string `json:"icon"`

	// The position of the channel, used for sorting in client.
	Position int `json:"position"`

	// The bitrate of the channel, if it is a voice channel.
	Bitrate int `json:"bitrate"`

	// The recipients of the channel. This is only populated in DM channels.
	Recipients []*User `json:"recipients"`

	// The messages in the channel. This is only present in state-cached channels,
	// and State.MaxMessageCount must be non-zero.
	Messages []*Message `json:"-"`

	// A list of permission overwrites present for the channel.
	PermissionOverwrites []*PermissionOverwrite `json:"permission_overwrites"`

	// The user limit of the voice channel.
	UserLimit int `json:"user_limit"`

	// amount of seconds a user has to wait before sending another message
	RateLimitPerUser int `json:"rate_limit_per_user"`

	// The ID of the parent channel, if the channel is under a category
	ParentID string `json:"parent_id"`

	// The Session to call the API and retrieve other objects
	Session *Session `json:"-"`
	// contains filtered or unexported fields
}

A Channel holds all data related to an individual Discord channel.

func (*Channel) ChangedRoles added in v0.20.9

func (c *Channel) ChangedRoles() (roles []*Role, err error)

ChangedRoles returns all roles where the default perms were overwritten.

func (*Channel) CreateInvite added in v0.20.7

func (c *Channel) CreateInvite(data *InviteBuilder) (i *Invite, err error)

CreateInvite creates an invite. data : the InviteBuilder with data for the invite creation

func (Channel) CreatedAt added in v0.20.0

func (c Channel) CreatedAt() (creation time.Time, err error)

CreatedAt returns the channels creation time in UTC

func (*Channel) Delete added in v0.20.7

func (c *Channel) Delete() (err error)

Delete deletes the channel.

func (*Channel) DeleteMessage added in v0.20.4

func (c *Channel) DeleteMessage(message *Message) (err error)

DeleteMessage deletes a message from the channel. message : message to delete

func (*Channel) DeleteMessageByID added in v0.20.4

func (c *Channel) DeleteMessageByID(ID string) (err error)

DeleteMessageByID deletes a message with the given ID from the channel. ID : ID of the message to delete

func (*Channel) Edit added in v0.20.16

func (c *Channel) Edit(data *ChannelEdit) error

Edit edits the channel

func (Channel) EditMessage added in v0.20.0

func (c Channel) EditMessage(data *MessageEdit) (edited *Message, err error)

EditMessage edits an existing message, replacing it entirely with the given MessageEdit struct

func (Channel) FetchMessage added in v0.20.0

func (c Channel) FetchMessage(ID string) (message *Message, err error)

FetchMessage fetches a message with the given ID from the channel. ID : ID of the message to fetch

func (*Channel) FetchPins added in v0.20.4

func (c *Channel) FetchPins() ([]*Message, error)

FetchPins fetches all pinned messages in the channel from the discord api.

func (Channel) GetHistory added in v0.20.0

func (c Channel) GetHistory(limit int, beforeID, afterID, aroundID string) (st []*Message, err error)

GetHistory fetches up to limit messages from the channel. limit : The number messages that can be returned. (max 100) beforeID : If provided all messages returned will be before given ID. afterID : If provided all messages returned will be after given ID. aroundID : If provided all messages returned will be around given ID.

func (Channel) GetHistoryIterator added in v0.20.15

func (c Channel) GetHistoryIterator() *HistoryIterator

GetHistoryIterator returns a bare HistoryIterator for this channel.

func (Channel) GetID added in v0.20.0

func (c Channel) GetID() string

GetID returns the ID of the channel.

func (*Channel) GetParent added in v0.20.9

func (c *Channel) GetParent() (*Channel, error)

GetParent returns the category that the channel belongs to, or returns an error if it doesn't.

func (*Channel) Guild added in v0.20.4

func (c *Channel) Guild() (g *Guild, err error)

Guild retrieves the guild belonging to the channel.

func (*Channel) HasPins added in v0.20.4

func (c *Channel) HasPins() bool

HasPins returns a bool indicating if a channel has pinned messages.

func (*Channel) MembersInVoice added in v0.20.32

func (c *Channel) MembersInVoice() (members []*Member, err error)

MembersInVoice returns all the members currently in this voice channel

func (Channel) Mention added in v0.20.0

func (c Channel) Mention() string

Mention returns a string which mentions the channel.

func (*Channel) MessagesBulkDelete added in v0.20.4

func (c *Channel) MessagesBulkDelete(messages []*Message) (err error)

MessagesBulkDelete bulk deletes the messages from the channel for the provided message objects. messages : The messages to be deleted. A slice of message objects. A maximum of 100 messages.

func (*Channel) MessagesBulkDeleteByID added in v0.20.4

func (c *Channel) MessagesBulkDeleteByID(messages []string) (err error)

MessagesBulkDeleteByID bulk deletes the messages from the channel for the provided messageIDs. If only one messageID is in the slice call channelMessageDelete function. If the slice is empty do nothing. messages : The IDs of the messages to be deleted. A slice of string IDs. A maximum of 100 messages.

func (*Channel) NewEdit added in v0.20.16

func (c *Channel) NewEdit() *ChannelEdit

NewEdit creates a new ChannelEdit to chain an edit with

func (*Channel) OverwritesFor added in v0.20.9

func (c *Channel) OverwritesFor(target IDGettable) (overwrite *PermissionOverwrite, err error)

OverwritesFor returns the overwrites for the given user or role in the channel.

func (*Channel) PermissionsFor added in v0.20.7

func (c *Channel) PermissionsFor(m *Member) (perms Permissions, err error)

PermissionsFor calculates the permissions that the member has in the channel, taking into account the following cases: - Guild owner - Guild roles - Channel overrides - Member overrides

func (*Channel) PermissionsSynced added in v0.20.9

func (c *Channel) PermissionsSynced() bool

PermissionsSynced returns true if the channel permissions are synced with their category.

func (Channel) SendMessage added in v0.20.0

func (c Channel) SendMessage(content string, embed *MessageEmbed, files []*File) (message *Message, err error)

SendMessage sends a message to the channel. content : message content to send if provided embed : embed to attach to the message if provided files : files to attach to the message if provided

func (Channel) SendMessageComplex added in v0.20.0

func (c Channel) SendMessageComplex(data *MessageSend) (message *Message, err error)

SendMessageComplex sends a message to the channel. data : MessageSend object with the data to send

func (*Channel) SetPermissions added in v0.20.7

func (c *Channel) SetPermissions(target IDGettable, overwrite *PermissionOverwrite) (err error)

SetPermissions sets or deletes a permission overwrite on the channel.

func (Channel) String added in v0.20.11

func (c Channel) String() string

String returns the name of the channel for easy formatting.

type ChannelCreate added in v0.11.0

type ChannelCreate struct {
	*Channel
}

ChannelCreate is the data for a ChannelCreate event.

type ChannelDelete added in v0.11.0

type ChannelDelete struct {
	*Channel
}

ChannelDelete is the data for a ChannelDelete event.

type ChannelEdit added in v0.18.0

type ChannelEdit struct {
	Name                 string                 `json:"name,omitempty"`
	Topic                string                 `json:"topic"`
	NSFW                 bool                   `json:"nsfw"`
	Position             int                    `json:"position"`
	Bitrate              int                    `json:"bitrate,omitempty"`
	UserLimit            int                    `json:"user_limit"`
	PermissionOverwrites []*PermissionOverwrite `json:"permission_overwrites,omitempty"`
	ParentID             string                 `json:"parent_id"`
	RateLimitPerUser     int                    `json:"rate_limit_per_user"`
}

A ChannelEdit holds Channel Field data for a channel edit.

func (*ChannelEdit) IsNSFW added in v0.20.16

func (c *ChannelEdit) IsNSFW() *ChannelEdit

IsNSFW can be used to set the channel to being NSFW in a chain

func (*ChannelEdit) IsNotNSFW added in v0.20.16

func (c *ChannelEdit) IsNotNSFW() *ChannelEdit

IsNotNSFW can be used to set the channel to not be NSFW in a chain

func (*ChannelEdit) SetBitrate added in v0.20.16

func (c *ChannelEdit) SetBitrate(bitrate int) *ChannelEdit

SetBitrate can be used to set the channel Bitrate in a chain

func (*ChannelEdit) SetName added in v0.20.16

func (c *ChannelEdit) SetName(name string) *ChannelEdit

SetName can be used to set the channel name in a chain

func (*ChannelEdit) SetParentID added in v0.20.16

func (c *ChannelEdit) SetParentID(ID string) *ChannelEdit

SetParentID can be used to set the ID of the parent channel in a chain

func (*ChannelEdit) SetPosition added in v0.20.16

func (c *ChannelEdit) SetPosition(pos int) *ChannelEdit

SetPosition can be used to set the channel position in a chain

func (*ChannelEdit) SetRateLimitPerUser added in v0.20.16

func (c *ChannelEdit) SetRateLimitPerUser(limit int) *ChannelEdit

SetRateLimitPerUser can be used to set the slowdown in the channel in a chain

func (*ChannelEdit) SetTopic added in v0.20.16

func (c *ChannelEdit) SetTopic(topic string) *ChannelEdit

SetTopic can be used to set the channel topic in a chain

type ChannelPinsUpdate added in v0.15.0

type ChannelPinsUpdate struct {
	LastPinTimestamp string `json:"last_pin_timestamp"`
	ChannelID        string `json:"channel_id"`
	GuildID          string `json:"guild_id,omitempty"`
}

ChannelPinsUpdate stores data for a ChannelPinsUpdate event.

type ChannelType added in v0.17.0

type ChannelType int

ChannelType is the type of a Channel.

const (
	ChannelTypeGuildText ChannelType = iota
	ChannelTypeDM
	ChannelTypeGuildVoice
	ChannelTypeGroupDM
	ChannelTypeGuildCategory
	ChannelTypeGuildNews
	ChannelTypeGuildStore
)

Block contains known ChannelType values.

type ChannelUpdate added in v0.11.0

type ChannelUpdate struct {
	*Channel
	BeforeUpdate *Channel `json:"-"`
}

ChannelUpdate is the data for a ChannelUpdate event.

type Color added in v0.20.9

type Color int

Color is a type around the int value of a discord color

func DefaultColor added in v0.20.9

func DefaultColor() Color

DefaultColor returns the Color object with a value of 0, the default color of discord roles

func (*Color) B added in v0.20.9

func (c *Color) B() int

B returns the blue component of the Color

func (*Color) G added in v0.20.9

func (c *Color) G() int

G returns the green component of the Color

func (*Color) R added in v0.20.9

func (c *Color) R() int

R returns the red component of the Color

func (*Color) SetHex added in v0.20.9

func (c *Color) SetHex(hex string) (err error)

SetHex sets the value of the color to the given hexcode string hex : the string containing the hex code of the color

func (*Color) SetRGB added in v0.20.9

func (c *Color) SetRGB(r, g, b int)

SetRGB sets the value of the color to the given RGB values r : the red component g : the green component b : the blue component

func (Color) String added in v0.20.9

func (c Color) String() string

String formats the Color into a string of the hexcode representing it

type Connect added in v0.11.0

type Connect struct{}

Connect is the data for a Connect event. This is a synthetic event and is not dispatched by Discord.

type Disconnect added in v0.11.0

type Disconnect struct{}

Disconnect is the data for a Disconnect event. This is a synthetic event and is not dispatched by Discord.

type Emoji added in v0.8.0

type Emoji struct {
	// The ID of the emoji, this is empty if the emoji is not custom
	ID string `json:"id"`

	// The name of the emoji, this is the unicode character of the emoji if it's not custom
	Name string `json:"name"`

	// A list of roles that is allowed to use this emoji, if it is empty, the emoji is unrestricted.
	Roles []string `json:"roles"`

	// if the emoji is managed by an external service
	Managed bool `json:"managed"`

	// If colons are required to use this emoji in the client
	RequireColons bool `json:"require_colons"`

	// If the emoji is animated
	Animated bool `json:"animated"`

	// If the emoji is available to use
	Available bool `json:"available"`

	// The Session to call the API and retrieve other objects
	Session *Session `json:"-"`

	// the guild this emoji belongs to
	Guild *Guild `json:"-"`
}

Emoji struct holds data related to Emoji's

func (*Emoji) APIName added in v0.15.0

func (e *Emoji) APIName() string

APIName returns an correctly formatted API name for use in the MessageReactions endpoints.

func (Emoji) CreatedAt added in v0.20.6

func (e Emoji) CreatedAt() (creation time.Time, err error)

CreatedAt returns the emoji's creation time in UTC, will return an error if the emoji is not custom

func (*Emoji) Delete added in v0.20.4

func (e *Emoji) Delete() error

Delete deletes the emoji

func (*Emoji) EditName added in v0.20.4

func (e *Emoji) EditName(name string) (edited *Emoji, err error)

EditName edits the name of the custom emoji name : the new name for the custom emoji

func (Emoji) GetID added in v0.20.6

func (e Emoji) GetID() string

GetID returns the emoji's ID, this will be an empty string if the emoji is not custom

func (*Emoji) IsCustom added in v0.20.4

func (e *Emoji) IsCustom() bool

IsCustom returns true if the emoji is a custom emoji

func (*Emoji) IsEqual added in v0.20.6

func (e *Emoji) IsEqual(other *Emoji) bool

IsEqual returns true if the other emoji has the same ID if they are both custom and else true if they have the same name

func (*Emoji) LimitRoles added in v0.20.4

func (e *Emoji) LimitRoles(roles []*Role) (edited *Emoji, err error)

LimitRoles limits the use of the emoji to the roles given here, leave empty to make the emoji unrestricted roles : the list of roles to make the emoji exclusive to

func (*Emoji) MessageFormat added in v0.20.0

func (e *Emoji) MessageFormat() string

MessageFormat returns a correctly formatted Emoji for use in Message content and embeds

func (*Emoji) RoleObjects added in v0.20.4

func (e *Emoji) RoleObjects() (roles []*Role)

RoleObjects returns a slice of role objects, formed from the slice of strings that is the Roles attribute of Emoji

func (Emoji) String added in v0.20.6

func (e Emoji) String() string

String renders the string needed to display the emoji correctly in discord

type Event

type Event struct {
	Operation int             `json:"op"`
	Sequence  int64           `json:"s"`
	Type      string          `json:"t"`
	RawData   json.RawMessage `json:"d"`
	// Struct contains one of the other types in this file.
	Struct interface{} `json:"-"`
}

Event provides a basic initial struct for all websocket events.

type EventHandler added in v0.15.0

type EventHandler interface {
	// Type returns the type of event this handler belongs to.
	Type() string

	// Handle is called whenever an event of Type() happens.
	// It is the receivers responsibility to type assert that the interface
	// is the expected struct.
	Handle(*Session, interface{})
}

EventHandler is an interface for Discord events.

type EventInterfaceProvider added in v0.15.0

type EventInterfaceProvider interface {
	// Type is the type of event this handler belongs to.
	Type() string

	// New returns a new instance of the struct this event handler handles.
	// This is called once per event.
	// The struct is provided to all handlers of the same Type().
	New() interface{}
}

EventInterfaceProvider is an interface for providing empty interfaces for Discord events.

type ExplicitContentFilterLevel added in v0.20.0

type ExplicitContentFilterLevel int

ExplicitContentFilterLevel type definition

const (
	ExplicitContentFilterDisabled ExplicitContentFilterLevel = iota
	ExplicitContentFilterMembersWithoutRoles
	ExplicitContentFilterAllMembers
)

Constants for ExplicitContentFilterLevel levels from 0 to 2 inclusive

type File added in v0.16.0

type File struct {
	Name        string
	ContentType string
	Reader      io.Reader
}

File stores info about files you e.g. send in messages.

type Game added in v0.7.0

type Game struct {
	Name          string     `json:"name"`
	Type          GameType   `json:"type"`
	URL           string     `json:"url,omitempty"`
	Details       string     `json:"details,omitempty"`
	State         string     `json:"state,omitempty"`
	TimeStamps    TimeStamps `json:"timestamps,omitempty"`
	Assets        Assets     `json:"assets,omitempty"`
	ApplicationID string     `json:"application_id,omitempty"`
	Instance      int8       `json:"instance,omitempty"`
}

A Game struct holds the name of the "playing .." game for a user

type GameType added in v0.18.0

type GameType int

GameType is the type of "game" (see GameType* consts) in the Game struct

const (
	GameTypeGame GameType = iota
	GameTypeStreaming
	GameTypeListening
	GameTypeWatching
)

Valid GameType values

type GatewayBotResponse added in v0.17.0

type GatewayBotResponse struct {
	URL    string `json:"url"`
	Shards int    `json:"shards"`
}

GatewayBotResponse stores the data for the gateway/bot response

type Guild

type Guild struct {
	// The ID of the guild.
	ID string `json:"id"`

	// The name of the guild. (2–100 characters)
	Name string `json:"name"`

	// The hash of the guild's icon. Use Session.GuildIcon
	// to retrieve the icon itself.
	Icon string `json:"icon"`

	// The voice region of the guild.
	Region string `json:"region"`

	// The ID of the AFK voice channel.
	AfkChannelID string `json:"afk_channel_id"`

	// The ID of the embed channel ID, used for embed widgets.
	EmbedChannelID string `json:"embed_channel_id"`

	// The user ID of the owner of the guild.
	OwnerID string `json:"owner_id"`

	// The time at which the current user joined the guild.
	// This field is only present in GUILD_CREATE events and websocket
	// update events, and thus is only present in state-cached guilds.
	JoinedAt Timestamp `json:"joined_at"`

	// The hash of the guild's splash.
	Splash string `json:"splash"`

	// The timeout, in seconds, before a user is considered AFK in voice.
	AfkTimeout int `json:"afk_timeout"`

	// The number of members in the guild.
	// This field is only present in GUILD_CREATE events and websocket
	// update events, and thus is only present in state-cached guilds.
	MemberCount int `json:"member_count"`

	// The verification level required for the guild.
	VerificationLevel VerificationLevel `json:"verification_level"`

	// Whether the guild has embedding enabled.
	EmbedEnabled bool `json:"embed_enabled"`

	// Whether the guild is considered large. This is
	// determined by a member threshold in the identify packet,
	// and is currently hard-coded at 250 members in the library.
	Large bool `json:"large"`

	// The default message notification setting for the guild.
	// 0 == all messages, 1 == mentions only.
	DefaultMessageNotifications int `json:"default_message_notifications"`

	// A list of roles in the guild.
	Roles []*Role `json:"roles"`

	// A list of the custom emojis present in the guild.
	Emojis []*Emoji `json:"emojis"`

	// A list of the members in the guild.
	// This field is only present in GUILD_CREATE events and websocket
	// update events, and thus is only present in state-cached guilds.
	Members []*Member `json:"members"`

	// A list of partial presence objects for members in the guild.
	// This field is only present in GUILD_CREATE events and websocket
	// update events, and thus is only present in state-cached guilds.
	Presences []*Presence `json:"presences"`

	// A list of channels in the guild.
	// This field is only present in GUILD_CREATE events and websocket
	// update events, and thus is only present in state-cached guilds.
	Channels []*Channel `json:"channels"`

	// A list of voice states for the guild.
	// This field is only present in GUILD_CREATE events and websocket
	// update events, and thus is only present in state-cached guilds.
	VoiceStates []*VoiceState `json:"voice_states"`

	// Whether this guild is currently unavailable (most likely due to outage).
	// This field is only present in GUILD_CREATE events and websocket
	// update events, and thus is only present in state-cached guilds.
	Unavailable bool `json:"unavailable"`

	// The explicit content filter level
	ExplicitContentFilter ExplicitContentFilterLevel `json:"explicit_content_filter"`

	// The list of enabled guild features
	Features []string `json:"features"`

	// Required MFA level for the guild
	MfaLevel MfaLevel `json:"mfa_level"`

	// Whether or not the Server Widget is enabled
	WidgetEnabled bool `json:"widget_enabled"`

	// The Channel ID for the Server Widget
	WidgetChannelID string `json:"widget_channel_id"`

	// The Channel ID to which system messages are sent (eg join and leave messages)
	SystemChannelID string `json:"system_channel_id"`

	// the vanity url code for the guild
	VanityURLCode string `json:"vanity_url_code"`

	// the description for the guild
	Description string `json:"description"`

	// The hash of the guild's banner
	Banner string `json:"banner"`

	// The premium tier of the guild
	PremiumTier PremiumTier `json:"premium_tier"`

	// The total number of users currently boosting this server
	PremiumSubscriptionCount int `json:"premium_subscription_count"`

	// The Session to call the API and retrieve other objects
	Session *Session `json:"-"`
}

A Guild holds all data related to a specific Discord Guild. Guilds are also sometimes referred to as Servers in the Discord client.

func (*Guild) AuditLogs added in v0.20.0

func (g *Guild) AuditLogs(userID, beforeID string, actionType, limit int) (log *GuildAuditLog, err error)

AuditLogs returns the audit log of the Guild. userID : If provided the log will be filtered for the given ID. beforeID : If provided all log entries returned will be before the given ID. actionType : If provided the log will be filtered for the given Action Type. limit : The number messages that can be returned. (default 50, min 1, max 100)

func (*Guild) Ban added in v0.20.0

func (g *Guild) Ban(user *User, reason string, days int) error

Ban bans the given user from the guild. user : The User reason : The reason for this ban days : The number of days of previous comments to delete.

func (*Guild) BitrateLimit added in v0.20.0

func (g *Guild) BitrateLimit() int

BitrateLimit returns the maximum bitrate for voice channels this guild can have

func (*Guild) CreateChannel added in v0.20.0

func (g *Guild) CreateChannel(name string, channelType ChannelType) (channel *Channel, err error)

CreateChannel creates and returns a new channel in the guild name : Name of the channel (2-100 chars length) channelType : Type of the channel

func (*Guild) CreateRole added in v0.20.0

func (g *Guild) CreateRole(settings *RoleSettings) (role *Role, err error)

CreateRole creates and then returns a new Guild Role.

func (Guild) CreatedAt added in v0.20.0

func (g Guild) CreatedAt() (creation time.Time, err error)

CreatedAt returns the guilds creation time in UTC

func (*Guild) DeleteInvite added in v0.20.4

func (g *Guild) DeleteInvite(inviteID string) (*Invite, error)

DeleteInvite deletes the given invite from the guild

func (*Guild) Edit added in v0.20.28

func (g *Guild) Edit(edit *GuildParams) (st *Guild, err error)

Edit edits the guild with the given GuildParams edit : the GuildParams saying what to edit

func (*Guild) EmojiLimit added in v0.20.0

func (g *Guild) EmojiLimit() int

EmojiLimit returns the maximum amount of emojis that this guild can have

func (*Guild) FetchMembers added in v0.20.0

func (g *Guild) FetchMembers(max int, after string) (err error)

FetchMembers fetches count members of this guild from discord and adds them to the state. limit : The max amount of members to fetch (max 1000) after : The id of the member to return members after TODO: Make this use the websocket instead of the API

func (*Guild) FileSizeLimit added in v0.20.0

func (g *Guild) FileSizeLimit() int

FileSizeLimit returns the maximum number of bytes files can have when uploaded to this guild

func (*Guild) GetBan added in v0.20.13

func (g *Guild) GetBan(user *User) (ban *GuildBan, err error)

GetBan returns the ban object of the given user user : The User to get the ban object for

func (*Guild) GetBans added in v0.20.0

func (g *Guild) GetBans() (bans []*GuildBan, err error)

GetBans returns an array of GuildBan structures for all bans of the guild

func (*Guild) GetChannel added in v0.20.0

func (g *Guild) GetChannel(channelID string) (channel *Channel, err error)

GetChannel gets the channel with the given ID as it is stored in Guild.Channels channelID : The ID of the channel to search for

func (*Guild) GetChannelNamed added in v0.20.0

func (g *Guild) GetChannelNamed(name string) (channel *Channel, err error)

GetChannelNamed gets the channel with the given name as it is stored in Guild.Channels It is semi-case-sensitive; if a name matches full, the first channel with that name gets returned if a name matches but with different capitalization, the last channel with that name gets returned name : The name of the channel to search for

func (*Guild) GetDefaultRole added in v0.20.7

func (g *Guild) GetDefaultRole() *Role

GetDefaultRole gets the @everyone role that everyone has by default

func (*Guild) GetEmoji added in v0.20.43

func (g *Guild) GetEmoji(emojiID string) (emoji *Emoji, err error)

GetEmoji returns the emoji with the given ID emojiID : ID of the emoji that should be returned

func (Guild) GetID added in v0.20.0

func (g Guild) GetID() string

GetID returns the guilds ID

func (*Guild) GetIconURL added in v0.20.31

func (g *Guild) GetIconURL() string

GetIconURL returns the URL to the guild icon

func (*Guild) GetInvites added in v0.20.0

func (g *Guild) GetInvites() (invites []*Invite, err error)

GetInvites returns an array of Invite structures for the guild

func (*Guild) GetMember added in v0.20.0

func (g *Guild) GetMember(userID string) (member *Member, err error)

GetMember gets the member with the given ID from the guild. userID : The ID of the member to search for

func (*Guild) GetPresence added in v0.20.37

func (g *Guild) GetPresence(userID string) (presence *Presence, err error)

GetPresence returns the Presence of the member with the given userID userID : userID of the member whose Presence should be returned

func (*Guild) GetRole added in v0.20.0

func (g *Guild) GetRole(roleID string) (role *Role, err error)

GetRole gets the role with the given ID as it is stored in Guild.Roles

func (*Guild) GetRoleNamed added in v0.20.0

func (g *Guild) GetRoleNamed(name string) (role *Role, err error)

GetRoleNamed gets the role with the given name as it is stored in Guild.Roles It is semi-case-sensitive; if a name matches full, the first role with that name gets returned if a name matches but with different capitalization, the last role with that name gets returned

func (*Guild) GetVoiceState added in v0.20.28

func (g *Guild) GetVoiceState(userID string) (voice *VoiceState, err error)

GetVoiceState returns the the VoiceState of the member with the given userID userID : userID of the member whose VoiceState should be returned

func (*Guild) Kick added in v0.20.0

func (g *Guild) Kick(user *User, reason string) error

Kick kicks the given user from the guild. user : The User to kick reason : The reason for the kick

func (*Guild) Me added in v0.20.0

func (g *Guild) Me() (member *Member, err error)

Me retrieves the member object representing this client in the guild

func (*Guild) NewEdit added in v0.20.28

func (g *Guild) NewEdit() *GuildParams

NewEdit creates a new GuildParams to chain an edit with

func (Guild) String added in v0.20.11

func (g Guild) String() string

String returns the guild's name for easy formatting

func (*Guild) UnBan added in v0.20.0

func (g *Guild) UnBan(user *User) error

UnBan unbans the given user user : The User

type GuildAuditLog added in v0.20.0

type GuildAuditLog struct {
	Webhooks []struct {
		ChannelID string `json:"channel_id"`
		GuildID   string `json:"guild_id"`
		ID        string `json:"id"`
		Avatar    string `json:"avatar"`
		Name      string `json:"name"`
	} `json:"webhooks,omitempty"`
	Users []struct {
		Username      string `json:"username"`
		Discriminator string `json:"discriminator"`
		Bot           bool   `json:"bot"`
		ID            string `json:"id"`
		Avatar        string `json:"avatar"`
	} `json:"users,omitempty"`
	AuditLogEntries []*AuditLogEntry `json:"audit_log_entries"`
}

A GuildAuditLog stores data for a guild audit log.

type GuildBan added in v0.8.0

type GuildBan struct {
	Reason string `json:"reason"`
	User   *User  `json:"user"`
}

A GuildBan stores data for a guild ban.

type GuildBanAdd added in v0.11.0

type GuildBanAdd struct {
	User    *User  `json:"user"`
	GuildID string `json:"guild_id"`
}

GuildBanAdd is the data for a GuildBanAdd event.

type GuildBanRemove added in v0.11.0

type GuildBanRemove struct {
	User    *User  `json:"user"`
	GuildID string `json:"guild_id"`
}

GuildBanRemove is the data for a GuildBanRemove event.

type GuildChannelCreateData added in v0.20.0

type GuildChannelCreateData struct {
	Name                 string                 `json:"name"`
	Type                 ChannelType            `json:"type"`
	Topic                string                 `json:"topic,omitempty"`
	Bitrate              int                    `json:"bitrate,omitempty"`
	UserLimit            int                    `json:"user_limit,omitempty"`
	PermissionOverwrites []*PermissionOverwrite `json:"permission_overwrites,omitempty"`
	ParentID             string                 `json:"parent_id,omitempty"`
	NSFW                 bool                   `json:"nsfw,omitempty"`
}

GuildChannelCreateData is provided to GuildChannelCreateComplex

type GuildCreate added in v0.11.0

type GuildCreate struct {
	*Guild
}

GuildCreate is the data for a GuildCreate event.

type GuildDelete added in v0.11.0

type GuildDelete struct {
	*Guild
}

GuildDelete is the data for a GuildDelete event.

type GuildEmbed added in v0.13.0

type GuildEmbed struct {
	Enabled   bool   `json:"enabled"`
	ChannelID string `json:"channel_id"`
}

A GuildEmbed stores data for a guild embed.

type GuildEmojisUpdate added in v0.8.0

type GuildEmojisUpdate struct {
	GuildID string   `json:"guild_id"`
	Emojis  []*Emoji `json:"emojis"`
}

A GuildEmojisUpdate is the data for a guild emoji update event.

type GuildIntegrationsUpdate

type GuildIntegrationsUpdate struct {
	GuildID string `json:"guild_id"`
}

GuildIntegrationsUpdate is the data for a GuildIntegrationsUpdate event.

type GuildLimit added in v0.20.0

type GuildLimit struct {
	Emoji    Emoji
	Bitrate  int
	FileSize int
}

GuildLimit stores the information about the limits for the guild that can be boosted

type GuildMemberAdd added in v0.11.0

type GuildMemberAdd struct {
	*Member
}

GuildMemberAdd is the data for a GuildMemberAdd event.

type GuildMemberRemove added in v0.11.0

type GuildMemberRemove struct {
	*Member
}

GuildMemberRemove is the data for a GuildMemberRemove event.

type GuildMemberUpdate added in v0.11.0

type GuildMemberUpdate struct {
	*Member
	BeforeUpdate *Member `json:"-"`
}

GuildMemberUpdate is the data for a GuildMemberUpdate event.

type GuildMembersChunk added in v0.15.0

type GuildMembersChunk struct {
	GuildID string    `json:"guild_id"`
	Members []*Member `json:"members"`
}

A GuildMembersChunk is the data for a GuildMembersChunk event.

type GuildParams added in v0.12.0

type GuildParams struct {
	Name                        string             `json:"name,omitempty"`
	Region                      string             `json:"region,omitempty"`
	VerificationLevel           *VerificationLevel `json:"verification_level,omitempty"`
	DefaultMessageNotifications int                `json:"default_message_notifications,omitempty"` // TODO: Separate type?
	AfkChannelID                string             `json:"afk_channel_id,omitempty"`
	AfkTimeout                  int                `json:"afk_timeout,omitempty"`
	Icon                        string             `json:"icon,omitempty"`
	OwnerID                     string             `json:"owner_id,omitempty"`
	Splash                      string             `json:"splash,omitempty"`
}

A GuildParams stores all the data needed to update discord guild settings

func (*GuildParams) SetAfkChannel added in v0.20.28

func (g *GuildParams) SetAfkChannel(channel *Channel) *GuildParams

SetAfkChannel can be used to set the guild region in a chain

func (*GuildParams) SetAfkTimeout added in v0.20.28

func (g *GuildParams) SetAfkTimeout(timeout int) *GuildParams

SetAfkTimeout can be used to set the guild AfkTimeout in a chain

func (*GuildParams) SetDefaultMessageNotifications added in v0.20.28

func (g *GuildParams) SetDefaultMessageNotifications(setting int) *GuildParams

SetDefaultMessageNotifications can be used to set the guild DefaultMessageNotifications in a chain

func (*GuildParams) SetIcon added in v0.20.28

func (g *GuildParams) SetIcon(icon string) *GuildParams

SetIcon can be used to set the guild icon in a chain

func (*GuildParams) SetName added in v0.20.28

func (g *GuildParams) SetName(name string) *GuildParams

SetName can be used to set the guild name in a chain

func (*GuildParams) SetOwner added in v0.20.28

func (g *GuildParams) SetOwner(user *User) *GuildParams

SetOwner can be used to set the guild owner in a chain (this is only possible if the bot is the owner)

func (*GuildParams) SetRegion added in v0.20.28

func (g *GuildParams) SetRegion(region string) *GuildParams

SetRegion can be used to set the guild region in a chain

func (*GuildParams) SetSplash added in v0.20.28

func (g *GuildParams) SetSplash(splash string) *GuildParams

SetSplash can be used to set the guild Splash in a chain

func (*GuildParams) SetVerificationLevel added in v0.20.28

func (g *GuildParams) SetVerificationLevel(level VerificationLevel) *GuildParams

SetVerificationLevel can be used to set the guild VerificationLevel in a chain

type GuildRole

type GuildRole struct {
	Role    *Role  `json:"role"`
	GuildID string `json:"guild_id"`
}

A GuildRole stores data for guild roles.

type GuildRoleCreate added in v0.11.0

type GuildRoleCreate struct {
	*GuildRole
}

GuildRoleCreate is the data for a GuildRoleCreate event.

type GuildRoleDelete

type GuildRoleDelete struct {
	RoleID  string `json:"role_id"`
	GuildID string `json:"guild_id"`
	Role    *Role  `json:"-"`
}

A GuildRoleDelete is the data for a GuildRoleDelete event.

type GuildRoleUpdate added in v0.11.0

type GuildRoleUpdate struct {
	*GuildRole
	BeforeUpdate *Role `json:"-"`
}

GuildRoleUpdate is the data for a GuildRoleUpdate event.

type GuildUpdate added in v0.11.0

type GuildUpdate struct {
	*Guild
	BeforeUpdate *Guild `json:"-"`
}

GuildUpdate is the data for a GuildUpdate event.

type HistoryIterator added in v0.20.15

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

HistoryIterator contains the information needed to iterate over the history of a Messageable using HistoryIterator.Iter()

func NewHistoryIterator added in v0.20.15

func NewHistoryIterator(channel Messageable) *HistoryIterator

NewHistoryIterator creates a new HistoryIterator based on the given Messageable and using the defaults; limit = 100 and going from newest to oldest. channel : The Messageable to get the history from

func (*HistoryIterator) Iter added in v0.20.15

func (h *HistoryIterator) Iter() <-chan *Message

Iter allows for the iterator to actually iterate and thus be used in a for ... range expression.

func (*HistoryIterator) Reset added in v0.20.15

func (h *HistoryIterator) Reset() *HistoryIterator

Reset sets everything back to defaults

func (*HistoryIterator) Reverse added in v0.20.15

func (h *HistoryIterator) Reverse() *HistoryIterator

Reverse toggles reverse, by default reverse is off and messages are returned newest first

func (*HistoryIterator) SetAfter added in v0.20.15

func (h *HistoryIterator) SetAfter(afterID string) *HistoryIterator

SetAfter sets the message ID from which to iterate back from till the most recent or limit afterID : the Message ID

func (*HistoryIterator) SetAround added in v0.20.15

func (h *HistoryIterator) SetAround(aroundID string) *HistoryIterator

SetAround sets the message ID from which to get the surrounding messages (max 100) aroundID : the Message ID

func (*HistoryIterator) SetBefore added in v0.20.15

func (h *HistoryIterator) SetBefore(beforeID string) *HistoryIterator

SetBefore sets the message ID from which to iterate back to get the messages before it beforeID : the Message ID

func (*HistoryIterator) SetLimit added in v0.20.15

func (h *HistoryIterator) SetLimit(limit int) *HistoryIterator

SetLimit sets the limit for how much messages to fetch. limit : the limit to use

type ICEServer

type ICEServer struct {
	URL        string `json:"url"`
	Username   string `json:"username"`
	Credential string `json:"credential"`
}

A ICEServer stores data for a specific voice ICE server.

type IDGettable added in v0.20.0

type IDGettable interface {
	GetID() string
	CreatedAt() (creation time.Time, err error)
}

IDGettable objects are objects where it is possible to get a snowflake ID from

type IDWrapper added in v0.20.11

type IDWrapper struct {
	ID string
}

IDWrapper is a struct used to make a bare ID string into an IDGettable object, this can then be used to pass it to a function that accepts any IDGettable object

func (IDWrapper) CreatedAt added in v0.20.11

func (i IDWrapper) CreatedAt() (creation time.Time, err error)

CreatedAt returns the creation time in UTC of the object that the snowflake ID represents

func (IDWrapper) GetID added in v0.20.11

func (i IDWrapper) GetID() string

GetID returns the ID inside the IDWrapper

type Integration added in v0.20.0

type Integration struct {
	ID                string             `json:"id"`
	Name              string             `json:"name"`
	Type              string             `json:"type"`
	Enabled           bool               `json:"enabled"`
	Syncing           bool               `json:"syncing"`
	RoleID            string             `json:"role_id"`
	ExpireBehavior    int                `json:"expire_behavior"`
	ExpireGracePeriod int                `json:"expire_grace_period"`
	User              *User              `json:"user"`
	Account           IntegrationAccount `json:"account"`
	SyncedAt          Timestamp          `json:"synced_at"`
}

Integration stores integration information

type IntegrationAccount added in v0.20.0

type IntegrationAccount struct {
	ID   string `json:"id"`
	Name string `json:"name"`
}

IntegrationAccount is integration account information sent by the UserConnections endpoint

type Intent added in v0.20.42

type Intent int

Intent type definition

const (
	IntentGuilds Intent = 1 << iota
	IntentGuildMembers
	IntentGuildBans
	IntentGuildEmojis
	IntentGuildIntegrations
	IntentGuildWebhooks
	IntentGuildInvites
	IntentGuildVoiceStates
	IntentGuildPresences
	IntentGuildMessages
	IntentGuildMessageReactions
	IntentGuildMessageTyping
	IntentDirectMessages
	IntentDirectMessageReactions
	IntentMessageTyping
)

Constants for Intents

type Invite

type Invite struct {
	Guild     *Guild    `json:"guild"`
	Channel   *Channel  `json:"channel"`
	Inviter   *User     `json:"inviter"`
	Code      string    `json:"code"`
	CreatedAt Timestamp `json:"created_at"`
	MaxAge    int       `json:"max_age"`
	Uses      int       `json:"uses"`
	MaxUses   int       `json:"max_uses"`
	Revoked   bool      `json:"revoked"`
	Temporary bool      `json:"temporary"`
	Unique    bool      `json:"unique"`

	TargetUser     *User `json:"target_user"`
	TargetUserType int   `json:"target_user_type"`

	// will only be filled when using InviteWithCounts
	ApproximatePresenceCount int `json:"approximate_presence_count"`
	ApproximateMemberCount   int `json:"approximate_member_count"`
}

A Invite stores all data related to a specific Discord Guild or Channel invite.

func (*Invite) Delete added in v0.20.4

func (i *Invite) Delete() (err error)

Delete deletes the invite

type InviteBuilder added in v0.20.32

type InviteBuilder struct {
	MaxAge    int  `json:"max_age"`
	MaxUses   int  `json:"max_uses"`
	Temporary bool `json:"temporary"`
	Unique    bool `json:"unique"`
}

InviteBuilder is an object used to create an invite

func NewInviteBuilder added in v0.20.32

func NewInviteBuilder() *InviteBuilder

NewInviteBuilder creates a new InviteBuilder to chain with and use as data for creating an invite

func (*InviteBuilder) IsTemporary added in v0.20.32

func (i *InviteBuilder) IsTemporary() *InviteBuilder

IsTemporary can be used to set the invite to being temporary in a chain

func (*InviteBuilder) IsUnique added in v0.20.32

func (i *InviteBuilder) IsUnique() *InviteBuilder

IsUnique can be used to set the invite to being unique in a chain

func (*InviteBuilder) SetMaxAge added in v0.20.32

func (i *InviteBuilder) SetMaxAge(age int) *InviteBuilder

SetMaxAge can be used to set the invite max age in a chain

func (*InviteBuilder) SetMaxUses added in v0.20.32

func (i *InviteBuilder) SetMaxUses(uses int) *InviteBuilder

SetMaxUses can be used to set the invite max uses in a chain

type Member

type Member struct {
	// The guild ID on which the member exists.
	GuildID string `json:"guild_id"`

	// The time at which the member joined the guild, in ISO8601.
	JoinedAt Timestamp `json:"joined_at"`

	// The nickname of the member, if they have one.
	Nick string `json:"nick"`

	// Whether the member is deafened at a guild level.
	Deaf bool `json:"deaf"`

	// Whether the member is muted at a guild level.
	Mute bool `json:"mute"`

	// The underlying user on which the member is based.
	User *User `json:"user"`

	// A list of IDs of the roles which are possessed by the member.
	Roles []string `json:"roles"`

	// When the user used their Nitro boost on the server
	PremiumSince Timestamp `json:"premium_since"`
	// contains filtered or unexported fields
}

A Member stores user information for Guild members. A guild member represents a certain user's presence in a guild.

func (*Member) AddRole added in v0.20.0

func (m *Member) AddRole(role *Role, reason string) (err error)

AddRole adds a role to the member role : role to add reason : the reason for the role add

func (*Member) AddRoles added in v0.20.13

func (m *Member) AddRoles(roles []*Role, reason string) (err error)

AddRoles adds multiple roles to the member roles : roles to add reason : the reason for the role adds

func (*Member) AvatarURL added in v0.20.0

func (m *Member) AvatarURL(size string) string

AvatarURL returns a URL to the user's avatar.

size:    The size of the user's avatar as a power of two
         if size is an empty string, no size parameter will
         be added to the URL.

func (*Member) Ban added in v0.20.0

func (m *Member) Ban(reason string, days int) (err error)

Ban bans the member from their guild reason : reason for the ban as it will be displayed in the audit log days : days of messages to delete

func (Member) CreatedAt added in v0.20.0

func (m Member) CreatedAt() (creation time.Time, err error)

CreatedAt returns the members creation time in UTC

func (*Member) DisconnectFromVoice added in v0.20.13

func (m *Member) DisconnectFromVoice(reason string) (err error)

DisconnectFromVoice disconnects the member from whatever voice channel they are in reason : the reason for the disconnect

func (*Member) EditNickname added in v0.20.0

func (m *Member) EditNickname(nick string) (err error)

EditNickname sets the nickname of the member nick : the new nickname the member will have

func (*Member) EditRoles added in v0.20.0

func (m *Member) EditRoles(roles Roles, reason string) (err error)

EditRoles replaces all roles of the user with the provided slice of roles roles : a slice of Role objects reason : the reason for the change in roles

func (*Member) GetColor added in v0.20.0

func (m *Member) GetColor() (color Color, err error)

GetColor returns the hex code of the members color as displayed in the server

func (*Member) GetDisplayName added in v0.20.0

func (m *Member) GetDisplayName() string

GetDisplayName returns the members nick if one has been set and else their username

func (*Member) GetGuild added in v0.20.0

func (m *Member) GetGuild() (g *Guild, err error)

GetGuild returns the guild object where the Member belongs to

func (Member) GetID added in v0.20.0

func (m Member) GetID() string

GetID returns the members ID

func (*Member) GetRoles added in v0.20.0

func (m *Member) GetRoles() (roles []*Role, err error)

GetRoles returns a slice with all roles the Member has, sorted from highest to lowest

func (*Member) GetTopRole added in v0.20.0

func (m *Member) GetTopRole() (role *Role, err error)

GetTopRole returns the members highest role

func (*Member) GetVoiceState added in v0.20.28

func (m *Member) GetVoiceState() (voice *VoiceState, err error)

GetVoiceState returns the members voice state

func (*Member) IsMentionedIn added in v0.20.0

func (m *Member) IsMentionedIn(message *Message) bool

IsMentionedIn checks if the member is mentioned in the given message message : message to check for mentions

func (*Member) IsOwner added in v0.20.12

func (m *Member) IsOwner() bool

IsOwner checks if the member is the owner of the guild they are in

func (*Member) Kick added in v0.20.0

func (m *Member) Kick(reason string) (err error)

Kick kicks the member from their guild reason : reason for the kick

func (Member) Mention added in v0.20.0

func (m Member) Mention() string

Mention creates a member mention

func (*Member) MoveTo added in v0.20.0

func (m *Member) MoveTo(channel *Channel, reason string) (err error)

MoveTo moves the member to a voice channel channel : voice channel to move the user to reason : the reason for the move

func (*Member) RemoveRole added in v0.20.0

func (m *Member) RemoveRole(role *Role, reason string) (err error)

RemoveRole removes a role from the member role : role to remove reason : the reason for the role remove

func (*Member) RemoveRoles added in v0.20.13

func (m *Member) RemoveRoles(roles []*Role, reason string) (err error)

RemoveRoles removes multiple roles from the member roles : roles to remove reason : the reason for the role removes

func (Member) String added in v0.20.0

func (m Member) String() string

String returns a unique identifier of the form displayName#discriminator

type Mentionable added in v0.20.0

type Mentionable interface {
	IDGettable
	Mention() string
}

Mentionable objects are objects that can have their snowflake ID be formatted as a mention in discord

type Message

type Message struct {
	// The ID of the message.
	ID string `json:"id"`

	// The ID of the channel in which the message was sent.
	ChannelID string `json:"channel_id"`

	// The ID of the guild in which the message was sent.
	GuildID string `json:"guild_id,omitempty"`

	// The content of the message.
	Content string `json:"content"`

	// The time at which the messsage was sent.
	// CAUTION: this field may be removed in a
	// future API version; it is safer to calculate
	// the creation time via the ID.
	Timestamp Timestamp `json:"timestamp"`

	// The time at which the last edit of the message
	// occurred, if it has been edited.
	EditedTimestamp Timestamp `json:"edited_timestamp"`

	// The roles mentioned in the message.
	MentionRoles []string `json:"mention_roles"`

	// Whether the message is text-to-speech.
	Tts bool `json:"tts"`

	// Whether the message mentions everyone.
	MentionEveryone bool `json:"mention_everyone"`

	// The author of the message. This is not guaranteed to be a
	// valid user (webhook-sent messages do not possess a full author).
	Author *User `json:"author"`

	// A list of attachments present in the message.
	Attachments []*MessageAttachment `json:"attachments"`

	// A list of embeds present in the message. Multiple
	// embeds can currently only be sent by webhooks.
	Embeds []*MessageEmbed `json:"embeds"`

	// A list of users mentioned in the message.
	Mentions []*User `json:"mentions"`

	// A list of reactions to the message.
	Reactions []*MessageReactions `json:"reactions"`

	// If the message has been pinned to the channel
	Pinned bool `json:"pinned"`

	// The type of the message.
	Type MessageType `json:"type"`

	// The webhook ID of the message, if it was generated by a webhook
	WebhookID string `json:"webhook_id"`

	// Member properties for this message's author,
	// contains only partial information
	Member *Member `json:"member"`

	// Channels specifically mentioned in this message
	// Not all channel mentions in a message will appear in mention_channels.
	// Only textual channels that are visible to everyone in a lurkable guild will ever be included.
	// Only crossposted messages (via Channel Following) currently include mention_channels at all.
	// If no mentions in the message meet these requirements, this field will not be sent.
	MentionChannels []*Channel `json:"mention_channels"`

	// Is sent with Rich Presence-related chat embeds
	Activity *MessageActivity `json:"activity"`

	// Is sent with Rich Presence-related chat embeds
	Application *MessageApplication `json:"application"`

	// MessageReference contains reference data sent with crossposted messages
	MessageReference *MessageReference `json:"message_reference"`

	// The flags of the message, which describe extra features of a message.
	// This is a combination of bit masks; the presence of a certain permission can
	// be checked by performing a bitwise AND between this int and the flag.
	Flags MessageFlag `json:"flags"`

	// The Session to call the API and retrieve other objects
	Session *Session `json:"-"`
}

A Message stores all data related to a specific Discord message.

func (*Message) AddReaction added in v0.20.4

func (m *Message) AddReaction(emoji *Emoji) (err error)

AddReaction adds a reaction to the current message emoji : the emoji to add

func (*Message) Channel added in v0.20.4

func (m *Message) Channel() *Channel

Channel returns the channel object that the message was posted in, this should only ever be nil right after a RESUME or the initial connection

func (*Message) ContentWithMentionsReplaced added in v0.8.0

func (m *Message) ContentWithMentionsReplaced() (content string)

ContentWithMentionsReplaced will replace all @<id> mentions with the username of the mention.

func (*Message) ContentWithMoreMentionsReplaced added in v0.17.0

func (m *Message) ContentWithMoreMentionsReplaced() (content string, err error)

ContentWithMoreMentionsReplaced will replace all @<id> mentions with the username of the mention, but also role IDs and more.

func (Message) CreatedAt added in v0.20.0

func (m Message) CreatedAt() (creation time.Time, err error)

CreatedAt returns the messages creation time in UTC

func (*Message) Delete added in v0.20.4

func (m *Message) Delete() (err error)

Delete deletes the message

func (*Message) Edit added in v0.20.4

func (m *Message) Edit(data *MessageEdit) (edited *Message, err error)

Edit edits the message, replacing it entirely with the given MessageEdit struct

func (*Message) EmbedSuppressed added in v0.20.15

func (m *Message) EmbedSuppressed() bool

EmbedSuppressed returns true if the embed(s) of the message have been suppressed

func (Message) GetID added in v0.20.0

func (m Message) GetID() string

GetID returns the ID of the message

func (*Message) Guild added in v0.20.4

func (m *Message) Guild() *Guild

Guild returns the guild a message was posted in if applicable, else guild is nil

func (*Message) HasBeenCrossposted added in v0.20.15

func (m *Message) HasBeenCrossposted() bool

HasBeenCrossposted returns true if the message has been crossposted (published) through channel following

func (*Message) IsCrosspost added in v0.20.15

func (m *Message) IsCrosspost() bool

IsCrosspost returns true if the message is a crosspost through channel following

func (*Message) JumpURL added in v0.20.4

func (m *Message) JumpURL() string

JumpURL returns the url to jump to the message

func (*Message) NewMessageEdit added in v0.20.4

func (m *Message) NewMessageEdit() *MessageEdit

NewMessageEdit returns a MessageEdit struct, initialized with the Channel and message ID.

func (*Message) Pin added in v0.20.4

func (m *Message) Pin() (err error)

Pin pins the message

func (*Message) RemoveAllReactions added in v0.20.4

func (m *Message) RemoveAllReactions() (err error)

RemoveAllReactions removes all the reactions from the message

func (*Message) RemoveReaction added in v0.20.4

func (m *Message) RemoveReaction(emoji *Emoji, user IDGettable) (err error)

RemoveReaction removes the reaction added by user from the message emoji : the emoji to remove user : the user or member who added the reaction

func (*Message) UnPin added in v0.20.4

func (m *Message) UnPin() (err error)

UnPin unpins the message

type MessageAck

type MessageAck struct {
	MessageID string `json:"message_id"`
	ChannelID string `json:"channel_id"`
}

MessageAck is the data for a MessageAck event.

type MessageActivity added in v0.20.31

type MessageActivity struct {
	Type    MessageActivityType `json:"type"`
	PartyID string              `json:"party_id"`
}

MessageActivity is sent with Rich Presence-related chat embeds

type MessageActivityType added in v0.20.31

type MessageActivityType int

MessageActivityType is the type of message activity

const (
	MessageActivityTypeJoin MessageActivityType = iota + 1
	MessageActivityTypeSpectate
	MessageActivityTypeListen
	MessageActivityTypeJoinRequest
)

Constants for the different types of Message Activity

type MessageApplication added in v0.20.31

type MessageApplication struct {
	ID          string `json:"id"`
	CoverImage  string `json:"cover_image"`
	Description string `json:"description"`
	Icon        string `json:"icon"`
	Name        string `json:"name"`
}

MessageApplication is sent with Rich Presence-related chat embeds

type MessageAttachment added in v0.13.0

type MessageAttachment struct {
	ID       string `json:"id"`
	URL      string `json:"url"`
	ProxyURL string `json:"proxy_url"`
	Filename string `json:"filename"`
	Width    int    `json:"width"`
	Height   int    `json:"height"`
	Size     int    `json:"size"`
}

A MessageAttachment stores data for message attachments.

type MessageCreate added in v0.11.0

type MessageCreate struct {
	*Message
}

MessageCreate is the data for a MessageCreate event.

type MessageDelete

type MessageDelete struct {
	*Message
}

MessageDelete is the data for a MessageDelete event.

type MessageDeleteBulk added in v0.16.0

type MessageDeleteBulk struct {
	Messages  []string `json:"ids"`
	ChannelID string   `json:"channel_id"`
	GuildID   string   `json:"guild_id"`
}

MessageDeleteBulk is the data for a MessageDeleteBulk event

type MessageEdit added in v0.16.0

type MessageEdit struct {
	// The content of the message.
	Content *string `json:"content,omitempty"`

	// The embed attached to the message
	Embed *MessageEmbed `json:"embed,omitempty"`

	// The flags of the message, which describe extra features of a message.
	// This is a combination of bit masks; the presence of a certain permission can
	// be checked by performing a bitwise AND between this int and the flag. C
	Flags MessageFlag `json:"flags"`

	ID      string
	Channel string
	// contains filtered or unexported fields
}

MessageEdit is used to chain parameters via ChannelMessageEditComplex, which is also where you should get the instance from.

func NewMessageEdit added in v0.16.0

func NewMessageEdit(channelID string, messageID string) *MessageEdit

NewMessageEdit returns a MessageEdit struct, given a Channel ID and message ID.

func (*MessageEdit) Edit added in v0.20.36

func (m *MessageEdit) Edit() (res *Message, err error)

Edit takes the MessageEdit and edits the message, this only works when the MessageEdit was created with Message.NewMessageEdit()

func (*MessageEdit) SetContent added in v0.16.0

func (m *MessageEdit) SetContent(str string) *MessageEdit

SetContent is the same as setting the variable Content, except it doesn't take a pointer.

func (*MessageEdit) SetEmbed added in v0.16.0

func (m *MessageEdit) SetEmbed(embed *MessageEmbed) *MessageEdit

SetEmbed is a convenience function for setting the embed, so you can chain commands.

func (*MessageEdit) ToggleEmbedSuppression added in v0.20.36

func (m *MessageEdit) ToggleEmbedSuppression() *MessageEdit

ToggleEmbedSuppression toggles if the embeds in the message have been suppressed or not

type MessageEmbed added in v0.13.0

type MessageEmbed struct {
	URL         string                 `json:"url,omitempty"`
	Type        string                 `json:"type,omitempty"`
	Title       string                 `json:"title,omitempty"`
	Description string                 `json:"description,omitempty"`
	Timestamp   string                 `json:"timestamp,omitempty"`
	Color       Color                  `json:"color,omitempty"`
	Footer      *MessageEmbedFooter    `json:"footer,omitempty"`
	Image       *MessageEmbedImage     `json:"image,omitempty"`
	Thumbnail   *MessageEmbedThumbnail `json:"thumbnail,omitempty"`
	Video       *MessageEmbedVideo     `json:"video,omitempty"`
	Provider    *MessageEmbedProvider  `json:"provider,omitempty"`
	Author      *MessageEmbedAuthor    `json:"author,omitempty"`
	Fields      []*MessageEmbedField   `json:"fields,omitempty"`
}

An MessageEmbed stores data for message embeds.

func NewEmbed added in v0.20.4

func NewEmbed() *MessageEmbed

NewEmbed creates an empty MessageEmbed object that you can use to chain

func (*MessageEmbed) AddField added in v0.20.4

func (e *MessageEmbed) AddField(name, value string, inline bool) *MessageEmbed

AddField can be used to add an embed field in a chain name : the field name value : the field value inline : determines if the field should be placed inline or not

func (*MessageEmbed) ClearFields added in v0.20.4

func (e *MessageEmbed) ClearFields() *MessageEmbed

ClearFields removes all fields in a chain

func (*MessageEmbed) RemoveField added in v0.20.4

func (e *MessageEmbed) RemoveField(position int) *MessageEmbed

RemoveField removes the field at position in a chain position : the position of the field to remove

func (*MessageEmbed) SetAuthor added in v0.20.4

func (e *MessageEmbed) SetAuthor(name, url, iconURL string) *MessageEmbed

SetAuthor can be used to set the name, url and icon url of the author in a chain name : the author name url : the author url iconUrl : the url of the author icon

func (*MessageEmbed) SetAuthorName added in v0.20.4

func (e *MessageEmbed) SetAuthorName(name string) *MessageEmbed

SetAuthorName can be used to only set the name of the author in a chain name : the author name

func (*MessageEmbed) SetColor added in v0.20.4

func (e *MessageEmbed) SetColor(c Color) *MessageEmbed

SetColor can be used to set the embed color in a chain color : the embed color

func (*MessageEmbed) SetDescription added in v0.20.4

func (e *MessageEmbed) SetDescription(desc string) *MessageEmbed

SetDescription can be used to set the embed description in a chain desc : the embed description

func (*MessageEmbed) SetFieldAt added in v0.20.4

func (e *MessageEmbed) SetFieldAt(name, value string, inline bool, position int) *MessageEmbed

SetFieldAt replaces the field at position with new values in a chain name : the field name value : the field value inline : determines if the field should be placed inline or not position : the position of the field to replace

func (*MessageEmbed) SetFooter added in v0.20.4

func (e *MessageEmbed) SetFooter(text, url string) *MessageEmbed

SetFooter can be used to set the text and url of the embed footer in a chain text : the footer text url : the footer url

func (*MessageEmbed) SetFooterText added in v0.20.4

func (e *MessageEmbed) SetFooterText(text string) *MessageEmbed

SetFooterText can be used to only set the text of the embed footer in a chain text : the footer text

func (*MessageEmbed) SetImage added in v0.20.4

func (e *MessageEmbed) SetImage(url string) *MessageEmbed

SetImage sets the image url in a chain url : url of the image

func (*MessageEmbed) SetThumbnail added in v0.20.4

func (e *MessageEmbed) SetThumbnail(url string) *MessageEmbed

SetThumbnail sets the image url for the thumbnail in a chain url : url of the image

func (*MessageEmbed) SetTimestamp added in v0.20.9

func (e *MessageEmbed) SetTimestamp(timeStamp time.Time) *MessageEmbed

SetTimestamp sets the embed timestamp to a custom value

func (*MessageEmbed) SetTimestampNow added in v0.20.9

func (e *MessageEmbed) SetTimestampNow() *MessageEmbed

SetTimestampNow sets the embed timestamp to the current time in UTC

func (*MessageEmbed) SetTitle added in v0.20.4

func (e *MessageEmbed) SetTitle(title string) *MessageEmbed

SetTitle can be used to set the embed title in a chain title : the embed title

type MessageEmbedAuthor added in v0.15.0

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

MessageEmbedAuthor is a part of a MessageEmbed struct.

type MessageEmbedField added in v0.15.0

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

MessageEmbedField is a part of a MessageEmbed struct.

type MessageEmbedFooter added in v0.15.0

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

MessageEmbedFooter is a part of a MessageEmbed struct.

type MessageEmbedImage added in v0.15.0

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

MessageEmbedImage is a part of a MessageEmbed struct.

type MessageEmbedProvider added in v0.15.0

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

MessageEmbedProvider is a part of a MessageEmbed struct.

type MessageEmbedThumbnail added in v0.15.0

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

MessageEmbedThumbnail is a part of a MessageEmbed struct.

type MessageEmbedVideo added in v0.15.0

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

MessageEmbedVideo is a part of a MessageEmbed struct.

type MessageFlag added in v0.20.31

type MessageFlag int

MessageFlag describes an extra feature of the message

const (
	// This message has been published to subscribed channels (via Channel Following)
	MessageFlagCrossposted MessageFlag = 1 << iota
	// This message originated from a message in another channel (via Channel Following)
	MessageFlagIsCrosspost
	// Do not include any embeds when serializing this message
	MessageFlagSuppressEmbeds
)

Constants for the different bit offsets of Message Flags

type MessageReaction added in v0.15.0

type MessageReaction struct {
	UserID    string `json:"user_id"`
	MessageID string `json:"message_id"`
	Emoji     *Emoji `json:"emoji"`
	ChannelID string `json:"channel_id"`
	GuildID   string `json:"guild_id,omitempty"`

	Session *Session `json:"-"`
}

MessageReaction stores the data for a message reaction.

func (*MessageReaction) GetChannel added in v0.20.5

func (r *MessageReaction) GetChannel() (c *Channel, err error)

GetChannel retrieves the channel that the message that was reacted to was posted in

func (*MessageReaction) GetGuild added in v0.20.5

func (r *MessageReaction) GetGuild() (g *Guild, err error)

GetGuild retrieves the guild that the message that was reacted to was posted in, will return an error if it was in dms

func (*MessageReaction) GetMember added in v0.20.5

func (r *MessageReaction) GetMember() (m *Member, err error)

GetMember retrieves the member that added the reaction, will return an error if it was not in a guild

func (*MessageReaction) GetMessage added in v0.20.5

func (r *MessageReaction) GetMessage() (m *Message, err error)

GetMessage retrieves the message that was reacted to

func (*MessageReaction) GetUser added in v0.20.5

func (r *MessageReaction) GetUser() (u *User, err error)

GetUser retrieves the user that added the reaction

func (*MessageReaction) Remove added in v0.20.4

func (r *MessageReaction) Remove() error

Remove removes the reaction from the message it was added to

func (MessageReaction) String added in v0.20.11

func (r MessageReaction) String() string

String renders the string needed to display the emoji used in the reaction correctly in discord

type MessageReactionAdd added in v0.15.0

type MessageReactionAdd struct {
	*MessageReaction
}

MessageReactionAdd is the data for a MessageReactionAdd event.

type MessageReactionRemove added in v0.15.0

type MessageReactionRemove struct {
	*MessageReaction
}

MessageReactionRemove is the data for a MessageReactionRemove event.

type MessageReactionRemoveAll added in v0.16.0

type MessageReactionRemoveAll struct {
	*MessageReaction
}

MessageReactionRemoveAll is the data for a MessageReactionRemoveAll event.

type MessageReactions added in v0.15.0

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

MessageReactions holds a reactions object for a message.

type MessageReference added in v0.20.31

type MessageReference struct {
	MessageID string `json:"message_id"`
	ChannelID string `json:"channel_id"`
	GuildID   string `json:"guild_id"`
}

MessageReference contains reference data sent with crossposted messages

type MessageSend added in v0.16.0

type MessageSend struct {
	Content string        `json:"content,omitempty"`
	Embed   *MessageEmbed `json:"embed,omitempty"`
	Tts     bool          `json:"tts"`
	Files   []*File       `json:"-"`

	// TODO: Remove this when compatibility is not required.
	File *File `json:"-"`
	// contains filtered or unexported fields
}

MessageSend stores all parameters you can send with ChannelMessageSendComplex.

type MessageType added in v0.17.0

type MessageType int

MessageType is the type of Message

const (
	MessageTypeDefault MessageType = iota
	MessageTypeRecipientAdd
	MessageTypeRecipientRemove
	MessageTypeCall
	MessageTypeChannelNameChange
	MessageTypeChannelIconChange
	MessageTypeChannelPinnedMessage
	MessageTypeGuildMemberJoin
	MessageTypeUserPremiumGuildSubscription
	MessageTypeUserPremiumGuildSubscriptionTierOne
	MessageTypeUserPremiumGuildSubscriptionTierTwo
	MessageTypeUserPremiumGuildSubscriptionTierThree
	MessageTypeChannelFollowAdd
)

Block contains the valid known MessageType values

type MessageUpdate added in v0.11.0

type MessageUpdate struct {
	*Message
	// BeforeUpdate will be nil if the Message was not previously cached in the state cache.
	BeforeUpdate *Message `json:"-"`
}

MessageUpdate is the data for a MessageUpdate event.

type Messageable added in v0.20.0

type Messageable interface {
	// Sends a message to the channel
	SendMessage(content string, embed *MessageEmbed, files []*File) (message *Message, err error)
	SendMessageComplex(data *MessageSend) (message *Message, err error)
	EditMessage(data *MessageEdit) (edited *Message, err error)

	// gets a single message by ID from the channel
	// ID : the ID of a Message
	FetchMessage(ID string) (message *Message, err error)

	// returns an array of Message structures for messages within
	// a given channel.
	// channelID : The ID of a Channel.
	// limit     : The number messages that can be returned. (max 100)
	// beforeID  : If provided all messages returned will be before given ID.
	// afterID   : If provided all messages returned will be after given ID.
	// aroundID  : If provided all messages returned will be around given ID.
	GetHistory(limit int, beforeID, afterID, aroundID string) (st []*Message, err error)

	// GetHistoryIterator returns a bare HistoryIterator for this Messageable.
	GetHistoryIterator() *HistoryIterator
}

type MfaLevel added in v0.20.0

type MfaLevel int

MfaLevel type definition

const (
	MfaLevelNone MfaLevel = iota
	MfaLevelElevated
)

Constants for MfaLevel levels from 0 to 1 inclusive

type Packet added in v0.11.0

type Packet struct {
	SSRC      uint32
	Sequence  uint16
	Timestamp uint32
	Type      []byte
	Opus      []byte
	PCM       []int16
}

A Packet contains the headers and content of a received voice packet.

type PermissionOffset added in v0.20.7

type PermissionOffset uint

PermissionOffset is used to denote how large the bit offset is for a permission

func (PermissionOffset) String added in v0.20.43

func (p PermissionOffset) String() string

String returns the name of the PermissionOffset as it is in the discord UI

type PermissionOverwrite

type PermissionOverwrite struct {
	ID    string      `json:"id"`
	Type  string      `json:"type"`
	Deny  Permissions `json:"deny"`
	Allow Permissions `json:"allow"`
}

A PermissionOverwrite holds permission overwrite data for a Channel

func (*PermissionOverwrite) Has added in v0.20.7

Has returns the value that has been set for a given permission in this overwrite it will return true for explicit allow, false for explicit deny and nil for if nothing has been explicitly set

func (*PermissionOverwrite) Set added in v0.20.7

func (p *PermissionOverwrite) Set(perm PermissionOffset, value *bool)

Set sets the permission overwrite value, the default value is not true or false, but nil

func (*PermissionOverwrite) ToMap added in v0.20.41

func (p *PermissionOverwrite) ToMap() map[string]*bool

ToMap converts the PermissionOverwrite to a key-value based representation of the overwrite

type Permissions added in v0.20.7

type Permissions int

Permissions is a type around the int value of a discord permission

func NewAllChannelPermissions added in v0.20.7

func NewAllChannelPermissions() Permissions

NewAllChannelPermissions is a factory function to create a Permissions object with all channel-specific permissions set to true

func NewAllPermissions added in v0.20.7

func NewAllPermissions() Permissions

NewAllPermissions is a factory function to create a Permissions object with all permissions set to true

func NewGeneralPermissions added in v0.20.7

func NewGeneralPermissions() Permissions

NewGeneralPermissions is a factory function to create a Permissions object with all general permissions from the official Discord UI set to true

func NewTextPermissions added in v0.20.7

func NewTextPermissions() Permissions

NewTextPermissions is a factory function to create a Permissions object with all text permissions from the official Discord UI set to true

func NewVoicePermissions added in v0.20.7

func NewVoicePermissions() Permissions

NewVoicePermissions is a factory function to create a Permissions object with all voice permissions from the official Discord UI set to true

func (*Permissions) HandleOverwrite added in v0.20.7

func (p *Permissions) HandleOverwrite(allow, deny Permissions) Permissions

HandleOverwrite returns a Permissions object that has taken the overwrites into account

func (*Permissions) Has added in v0.20.7

func (p *Permissions) Has(perm PermissionOffset) bool

Has returns if the Permissions object has a certain permission

func (*Permissions) IsSubset added in v0.20.7

func (p *Permissions) IsSubset(other *Permissions) bool

IsSubset returns true if the permissions object has the same or more permissions as other.

func (*Permissions) IsSuperset added in v0.20.7

func (p *Permissions) IsSuperset(other *Permissions) bool

IsSuperset returns true if the permissions object has the same or fewer permissions as other.

func (*Permissions) Set added in v0.20.7

func (p *Permissions) Set(perm PermissionOffset, value bool)

Set sets a permission on the Permissions object

func (*Permissions) ToMap added in v0.20.41

func (p *Permissions) ToMap() map[string]bool

ToMap converts the Permissions to a key-value based representation

type PremiumTier added in v0.20.0

type PremiumTier int

PremiumTier type definition

const (
	PremiumTierNone PremiumTier = iota
	PremiumTier1
	PremiumTier2
	PremiumTier3
)

Constants for PremiumTier levels from 0 to 3 inclusive

type PremiumType added in v0.20.15

type PremiumType int

PremiumType type definition

const (
	NoNitro PremiumType = iota
	NitroClassic
	Nitro
)

Constants for PremiumTypes Nitro and Nitro Classic

type Presence

type Presence struct {
	User   *User    `json:"user"`
	Status Status   `json:"status"`
	Game   *Game    `json:"game"`
	Nick   string   `json:"nick"`
	Roles  []string `json:"roles"`
	Since  *int     `json:"since"`
}

A Presence stores the online, offline, or idle and game status of Guild members.

type PresenceUpdate

type PresenceUpdate struct {
	Presence
	GuildID      string    `json:"guild_id"`
	Roles        []string  `json:"roles"`
	BeforeUpdate *Presence `json:"-"`
}

PresenceUpdate is the data for a PresenceUpdate event.

type PresencesReplace added in v0.12.0

type PresencesReplace []*Presence

PresencesReplace is the data for a PresencesReplace event.

type RESTError added in v0.15.0

type RESTError struct {
	Request      *http.Request
	Response     *http.Response
	ResponseBody []byte

	Message *APIErrorMessage // Message may be nil.
}

RESTError stores error information about a request with a bad response code. Message is not always present, there are cases where api calls can fail without returning a json message.

func (RESTError) Error added in v0.15.0

func (r RESTError) Error() string

type RateLimit added in v0.9.0

type RateLimit struct {
	*TooManyRequests
	URL string
}

RateLimit is the data for a RateLimit event. This is a synthetic event and is not dispatched by Discord.

type RateLimiter added in v0.15.0

type RateLimiter struct {
	sync.Mutex
	// contains filtered or unexported fields
}

RateLimiter holds all ratelimit buckets

func NewRatelimiter added in v0.15.0

func NewRatelimiter() *RateLimiter

NewRatelimiter returns a new RateLimiter

func (*RateLimiter) GetBucket added in v0.18.0

func (r *RateLimiter) GetBucket(key string) *Bucket

GetBucket retrieves or creates a bucket

func (*RateLimiter) GetWaitTime added in v0.18.0

func (r *RateLimiter) GetWaitTime(b *Bucket, minRemaining int) time.Duration

GetWaitTime returns the duration you should wait for a Bucket

func (*RateLimiter) LockBucket added in v0.15.0

func (r *RateLimiter) LockBucket(bucketID string) *Bucket

LockBucket Locks until a request can be made

func (*RateLimiter) LockBucketObject added in v0.18.0

func (r *RateLimiter) LockBucketObject(b *Bucket) *Bucket

LockBucketObject Locks an already resolved bucket until a request can be made

type ReadState

type ReadState struct {
	MentionCount  int    `json:"mention_count"`
	LastMessageID string `json:"last_message_id"`
	ID            string `json:"id"`
}

A ReadState stores data on the read state of channels.

type Ready

type Ready struct {
	Version         int          `json:"v"`
	SessionID       string       `json:"session_id"`
	User            *User        `json:"user"`
	ReadState       []*ReadState `json:"read_state"`
	PrivateChannels []*Channel   `json:"private_channels"`
	Guilds          []*Guild     `json:"guilds"`

	// Undocumented fields
	Presences []*Presence `json:"presences"`
}

A Ready stores all data for the websocket READY event.

type RestCache added in v0.20.17

type RestCache interface {
	Set(string, []byte) error
	Get(string) ([]byte, bool)
}

RestCache represents a basic REST caching service

type Resumed added in v0.13.0

type Resumed struct {
	Trace []string `json:"_trace"`
}

Resumed is the data for a Resumed event.

type Role

type Role struct {
	// The ID of the role.
	ID string `json:"id"`

	// The name of the role.
	Name string `json:"name"`

	// Whether this role is managed by an integration, and
	// thus cannot be manually added to, or taken from, members.
	Managed bool `json:"managed"`

	// Whether this role is mentionable.
	Mentionable bool `json:"mentionable"`

	// Whether this role is hoisted (shows up separately in member list).
	Hoist bool `json:"hoist"`

	// The hex color of this role.
	Color Color `json:"color"`

	// The position of this role in the guild's role hierarchy.
	Position int `json:"position"`

	// The permissions of the role on the guild (doesn't include channel overrides).
	// This is a combination of bit masks; the presence of a certain permission can
	// be checked by performing a bitwise AND between this int and the permission.
	Permissions Permissions `json:"permissions"`

	// ID of the guild this role belongs to
	Guild *Guild `json:"-"`

	// The Session to call the API and retrieve other objects
	Session *Session `json:"-"`
}

A Role stores information about Discord guild member roles.

func (Role) CreatedAt added in v0.20.0

func (r Role) CreatedAt() (creation time.Time, err error)

CreatedAt returns the roles creation time in UTC

func (*Role) Delete added in v0.20.0

func (r *Role) Delete() (err error)

Delete deletes the role

func (*Role) Edit added in v0.20.0

func (r *Role) Edit(name string, color Color, hoist bool, perm Permissions, mention bool) (edited *Role, err error)

Edit updates the Role with new values name : The name of the Role. color : The color of the role (decimal, not hex). hoist : Whether to display the role's users separately. perm : The permissions for the role. mention : Whether this role is mentionable

func (*Role) EditComplex added in v0.20.0

func (r *Role) EditComplex(data *RoleSettings) (edited *Role, err error)

EditComplex updates the Role with new values data : data to send to the API

func (Role) GetID added in v0.20.0

func (r Role) GetID() string

GetID returns the ID of the Role

func (*Role) GetMembers added in v0.20.0

func (r *Role) GetMembers() (members []*Member, err error)

GetMembers returns a slice with all members in the guild with this role

func (*Role) HigherThan added in v0.20.11

func (r *Role) HigherThan(other *Role) bool

HigherThan returns true if the role is higher in the role hierarchy than the other

func (*Role) IsDefault added in v0.20.0

func (r *Role) IsDefault() bool

IsDefault checks if the Role is the default (@everyone) role

func (*Role) LowerThan added in v0.20.11

func (r *Role) LowerThan(other *Role) bool

LowerThan returns true if the role is lower in the role hierarchy than the other

func (Role) Mention added in v0.20.0

func (r Role) Mention() string

Mention returns a string which mentions the role

func (*Role) Move added in v0.20.0

func (r *Role) Move(position int) (err error)

Move changes the position of the role in the role hierarchy position : the new position of the role

func (*Role) NewEdit added in v0.20.28

func (r *Role) NewEdit() *RoleSettings

NewEdit creates a new RoleSettings to chain an edit with

func (Role) String added in v0.20.11

func (r Role) String() string

String returns the name of the role for easy formatting

type RoleMove added in v0.20.0

type RoleMove struct {
	// The role's ID
	ID string `json:"id"`

	// The position of this role in the guild's role hierarchy.
	Position int `json:"position"`
}

A RoleMove stores the information needed to change a role's position in the role hierarchy

type RoleSettings added in v0.20.37

type RoleSettings struct {
	// The role's name (overwrites existing)
	Name string `json:"name,omitempty"`

	// The color the role should have (as a decimal, not hex)
	Color Color `json:"color,omitempty"`

	// Whether to display the role's users separately (overwrites existing)
	Hoist bool `json:"hoist"`

	// The overall permissions number of the role (overwrites existing)
	Permissions Permissions `json:"permissions,omitempty"`

	// Whether this role is mentionable (overwrites existing)
	Mentionable bool `json:"mentionable"`
}

A RoleSettings stores information used to edit or create a Role

func (*RoleSettings) IsHoisted added in v0.20.37

func (r *RoleSettings) IsHoisted() *RoleSettings

IsHoisted can be used to set the role to being hoisted in a chain

func (*RoleSettings) IsMentionable added in v0.20.37

func (r *RoleSettings) IsMentionable() *RoleSettings

IsMentionable can be used to set the role to being mentionable in a chain

func (*RoleSettings) IsNotHoisted added in v0.20.37

func (r *RoleSettings) IsNotHoisted() *RoleSettings

IsNotHoisted can be used to set the role to not be hoisted in a chain

func (*RoleSettings) IsNotMentionable added in v0.20.37

func (r *RoleSettings) IsNotMentionable() *RoleSettings

IsNotMentionable can be used to set the role to not be mentionable in a chain

func (*RoleSettings) SetColor added in v0.20.37

func (r *RoleSettings) SetColor(color Color) *RoleSettings

SetColor can be used to set the role color in a chain

func (*RoleSettings) SetName added in v0.20.37

func (r *RoleSettings) SetName(name string) *RoleSettings

SetName can be used to set the role name in a chain

func (*RoleSettings) SetPermissions added in v0.20.37

func (r *RoleSettings) SetPermissions(perms Permissions) *RoleSettings

SetPermissions can be used to set the role permissions in a chain

type Roles added in v0.16.0

type Roles []*Role

Roles are a collection of Role

func (Roles) ContainsID added in v0.20.0

func (r Roles) ContainsID(ID string) bool

ContainsID checks if the slice of Role objects contains a role with the given ID ID : the ID to search for

func (Roles) Len added in v0.16.0

func (r Roles) Len() int

func (Roles) Less added in v0.16.0

func (r Roles) Less(i, j int) bool

func (Roles) Swap added in v0.16.0

func (r Roles) Swap(i, j int)

type Session

type Session struct {
	sync.RWMutex

	// Authentication token for this session
	Token string
	MFA   bool

	// Debug for printing JSON request/responses
	Debug    bool // Deprecated, will be removed.
	LogLevel int

	// Should the session reconnect the websocket on errors.
	ShouldReconnectOnError bool

	// Should the session request compressed websocket data.
	Compress bool

	// Sharding
	ShardID    int
	ShardCount int

	// Should state tracking be enabled.
	// State tracking is the best way for getting the the users
	// active guilds and the members of the guilds.
	StateEnabled bool

	// Whether or not to call event handlers synchronously.
	// e.g false = launch event handlers in their own goroutines.
	SyncEvents bool

	// Whether the Data Websocket is ready
	DataReady bool // NOTE: Maye be deprecated soon

	// Max number of REST API retries
	MaxRestRetries int

	// Whether the Voice Websocket is ready
	VoiceReady bool // NOTE: Deprecated.

	// Whether the UDP Connection is ready
	UDPReady bool // NOTE: Deprecated

	// Stores a mapping of guild id's to VoiceConnections
	VoiceConnections map[string]*VoiceConnection

	// Managed state object, updated internally with events when
	// StateEnabled is true.
	State StateCache

	// The http client used for REST requests
	Client *http.Client

	// The user agent used for REST APIs
	UserAgent string

	// Stores the last HeartbeatAck that was recieved (in UTC)
	LastHeartbeatAck time.Time

	// Stores the last Heartbeat sent (in UTC)
	LastHeartbeatSent time.Time

	// Intents to send to Discord
	Intents Intent

	// used to deal with rate limits
	Ratelimiter *RateLimiter

	// Represents a cache for the REST API
	RESTCache RestCache
	// contains filtered or unexported fields
}

A Session represents a connection to the Discord API.

func New

func New(args ...interface{}) (s *Session, err error)

New creates a new Discord session and will automate some startup tasks if given enough information to do so. Currently you can pass zero arguments and it will return an empty Discord session.

func (*Session) AddHandler added in v0.11.0

func (s *Session) AddHandler(handler interface{}) func()

AddHandler allows you to add an event handler that will be fired anytime the Discord WSAPI event that matches the function fires. The first parameter is a *Session, and the second parameter is a pointer to a struct corresponding to the event for which you want to listen.

eg:

Session.AddHandler(func(s *discordgo.Session, m *discordgo.MessageCreate) {
})

or:

Session.AddHandler(func(s *discordgo.Session, m *discordgo.PresenceUpdate) {
})

List of events can be found at this page, with corresponding names in the library for each event: https://discordapp.com/developers/docs/topics/gateway#event-names There are also synthetic events fired by the library internally which are available for handling, like Connect, Disconnect, and RateLimit. events.go contains all of the Discord WSAPI and synthetic events that can be handled.

The return value of this method is a function, that when called will remove the event handler.

func (*Session) AddHandlerOnce added in v0.15.0

func (s *Session) AddHandlerOnce(handler interface{}) func()

AddHandlerOnce allows you to add an event handler that will be fired the next time the Discord WSAPI event that matches the function fires. See AddHandler for more details.

func (*Session) Application added in v0.12.0

func (s *Session) Application(appID string) (st *Application, err error)

Application returns an Application structure of a specific Application

appID : The ID of an Application

func (*Session) ApplicationAssets added in v0.20.31

func (s *Session) ApplicationAssets(appID string) (ass []*Asset, err error)

ApplicationAssets returns an application's assets

func (*Session) ApplicationBotCreate added in v0.12.0

func (s *Session) ApplicationBotCreate(appID string) (st *User, err error)

ApplicationBotCreate creates an Application Bot Account

appID : The ID of an Application

NOTE: func name may change, if I can think up something better.

func (*Session) ApplicationCreate added in v0.12.0

func (s *Session) ApplicationCreate(ap *Application) (st *Application, err error)

ApplicationCreate creates a new Application

name : Name of Application / Bot
uris : Redirect URIs (Not required)

func (*Session) ApplicationDelete added in v0.12.0

func (s *Session) ApplicationDelete(appID string) (err error)

ApplicationDelete deletes an existing Application

appID : The ID of an Application

func (*Session) ApplicationUpdate added in v0.12.0

func (s *Session) ApplicationUpdate(appID string, ap *Application) (st *Application, err error)

ApplicationUpdate updates an existing Application

var : desc

func (*Session) Applications added in v0.12.0

func (s *Session) Applications() (st []*Application, err error)

Applications returns all applications for the authenticated user

func (*Session) Channel

func (s *Session) Channel(channelID string) (st *Channel, err error)

Channel returns a Channel structure of a specific Channel. will first try the state cache before querying the discord api channelID : The ID of the Channel you want returned.

func (*Session) ChannelDelete

func (s *Session) ChannelDelete(channelID string) (st *Channel, err error)

ChannelDelete deletes the given channel channelID : The ID of a Channel

func (*Session) ChannelEdit

func (s *Session) ChannelEdit(channelID, name string) (*Channel, error)

ChannelEdit edits the given channel channelID : The ID of a Channel name : The new name to assign the channel.

func (*Session) ChannelEditComplex added in v0.18.0

func (s *Session) ChannelEditComplex(channelID string, data *ChannelEdit) (st *Channel, err error)

ChannelEditComplex edits an existing channel, replacing the parameters entirely with ChannelEdit struct channelID : The ID of a Channel data : The channel struct to send

func (*Session) ChannelFileSend added in v0.11.0

func (s *Session) ChannelFileSend(channelID, name string, r io.Reader) (*Message, error)

ChannelFileSend sends a file to the given channel. channelID : The ID of a Channel. name: The name of the file. io.Reader : A reader for the file contents.

func (*Session) ChannelFileSendWithMessage added in v0.15.0

func (s *Session) ChannelFileSendWithMessage(channelID, content string, name string, r io.Reader) (*Message, error)

ChannelFileSendWithMessage sends a file to the given channel with an message. DEPRECATED. Use ChannelMessageSendComplex instead. channelID : The ID of a Channel. content: Optional Message content. name: The name of the file. io.Reader : A reader for the file contents.

func (*Session) ChannelInviteCreate

func (s *Session) ChannelInviteCreate(channelID string, data *InviteBuilder) (st *Invite, err error)

ChannelInviteCreate creates a new invite for the given channel. channelID : The ID of a Channel data : An InviteBuilder struct.

func (*Session) ChannelInvites

func (s *Session) ChannelInvites(channelID string) (st []*Invite, err error)

ChannelInvites returns an array of Invite structures for the given channel channelID : The ID of a Channel

func (*Session) ChannelMessage added in v0.13.0

func (s *Session) ChannelMessage(channelID, messageID string) (st *Message, err error)

ChannelMessage gets a single message by ID from a given channel. channeld : The ID of a Channel messageID : the ID of a Message

func (*Session) ChannelMessageAck

func (s *Session) ChannelMessageAck(channelID, messageID, lastToken string) (st *Ack, err error)

ChannelMessageAck acknowledges and marks the given message as read channeld : The ID of a Channel messageID : the ID of a Message lastToken : token returned by last ack

func (*Session) ChannelMessageDelete

func (s *Session) ChannelMessageDelete(channelID, messageID string) (err error)

ChannelMessageDelete deletes a message from the Channel.

func (*Session) ChannelMessageEdit

func (s *Session) ChannelMessageEdit(channelID, messageID, content string) (*Message, error)

ChannelMessageEdit edits an existing message, replacing it entirely with the given content. channelID : The ID of a Channel messageID : The ID of a Message content : The contents of the message

func (*Session) ChannelMessageEditComplex added in v0.16.0

func (s *Session) ChannelMessageEditComplex(m *MessageEdit) (st *Message, err error)

ChannelMessageEditComplex edits an existing message, replacing it entirely with the given MessageEdit struct

func (*Session) ChannelMessageEditEmbed added in v0.15.0

func (s *Session) ChannelMessageEditEmbed(channelID, messageID string, embed *MessageEmbed) (*Message, error)

ChannelMessageEditEmbed edits an existing message with embedded data. channelID : The ID of a Channel messageID : The ID of a Message embed : The embed data to send

func (*Session) ChannelMessagePin added in v0.13.0

func (s *Session) ChannelMessagePin(channelID, messageID string) (err error)

ChannelMessagePin pins a message within a given channel. channelID: The ID of a channel. messageID: The ID of a message.

func (*Session) ChannelMessageSend

func (s *Session) ChannelMessageSend(channelID string, content string) (*Message, error)

ChannelMessageSend sends a message to the given channel. channelID : The ID of a Channel. content : The message to send.

func (*Session) ChannelMessageSendComplex added in v0.16.0

func (s *Session) ChannelMessageSendComplex(channelID string, data *MessageSend) (st *Message, err error)

ChannelMessageSendComplex sends a message to the given channel. channelID : The ID of a Channel. data : The message struct to send.

func (*Session) ChannelMessageSendEmbed added in v0.15.0

func (s *Session) ChannelMessageSendEmbed(channelID string, embed *MessageEmbed) (*Message, error)

ChannelMessageSendEmbed sends a message to the given channel with embedded data. channelID : The ID of a Channel. embed : The embed data to send.

func (*Session) ChannelMessageSendTTS added in v0.11.0

func (s *Session) ChannelMessageSendTTS(channelID string, content string) (*Message, error)

ChannelMessageSendTTS sends a message to the given channel with Text to Speech. channelID : The ID of a Channel. content : The message to send.

func (*Session) ChannelMessageUnpin added in v0.13.0

func (s *Session) ChannelMessageUnpin(channelID, messageID string) (err error)

ChannelMessageUnpin unpins a message within a given channel. channelID: The ID of a channel. messageID: The ID of a message.

func (*Session) ChannelMessages

func (s *Session) ChannelMessages(channelID string, limit int, beforeID, afterID, aroundID string) (st []*Message, err error)

ChannelMessages returns an array of Message structures for messages within a given channel. channelID : The ID of a Channel. limit : The number messages that can be returned. (max 100) beforeID : If provided all messages returned will be before given ID. afterID : If provided all messages returned will be after given ID. aroundID : If provided all messages returned will be around given ID.

func (*Session) ChannelMessagesBulkDelete added in v0.13.0

func (s *Session) ChannelMessagesBulkDelete(channelID string, messages []string) (err error)

ChannelMessagesBulkDelete bulk deletes the messages from the channel for the provided messageIDs. If only one messageID is in the slice call channelMessageDelete function. If the slice is empty do nothing. channelID : The ID of the channel for the messages to delete. messages : The IDs of the messages to be deleted. A slice of string IDs. A maximum of 100 messages.

func (*Session) ChannelMessagesPinned added in v0.13.0

func (s *Session) ChannelMessagesPinned(channelID string) (st []*Message, err error)

ChannelMessagesPinned returns an array of Message structures for pinned messages within a given channel channelID : The ID of a Channel.

func (*Session) ChannelPermissionDelete added in v0.7.0

func (s *Session) ChannelPermissionDelete(channelID, targetID string) (err error)

ChannelPermissionDelete deletes a specific permission override for the given channel. NOTE: Name of this func may change.

func (*Session) ChannelPermissionSet added in v0.7.0

func (s *Session) ChannelPermissionSet(channelID, targetID, targetType string, allow, deny Permissions) (err error)

ChannelPermissionSet creates a Permission Override for the given channel. NOTE: This func name may changed. Using Set instead of Create because you can both create a new override or update an override with this function.

func (*Session) ChannelTyping

func (s *Session) ChannelTyping(channelID string) (err error)

ChannelTyping broadcasts to all members that authenticated user is typing in the given channel. channelID : The ID of a Channel

func (*Session) ChannelVoiceJoin added in v0.9.0

func (s *Session) ChannelVoiceJoin(gID, cID string, mute, deaf bool) (voice *VoiceConnection, err error)

ChannelVoiceJoin joins the session user to a voice channel.

gID     : Guild ID of the channel to join.
cID     : Channel ID of the channel to join.
mute    : If true, you will be set to muted upon joining.
deaf    : If true, you will be set to deafened upon joining.

func (*Session) ChannelVoiceJoinManual added in v0.20.0

func (s *Session) ChannelVoiceJoinManual(gID, cID string, mute, deaf bool) (err error)

ChannelVoiceJoinManual initiates a voice session to a voice channel, but does not complete it.

This should only be used when the VoiceServerUpdate will be intercepted and used elsewhere.

gID     : Guild ID of the channel to join.
cID     : Channel ID of the channel to join, leave empty to disconnect.
mute    : If true, you will be set to muted upon joining.
deaf    : If true, you will be set to deafened upon joining.

func (*Session) ChannelWebhooks added in v0.15.0

func (s *Session) ChannelWebhooks(channelID string) (st []*Webhook, err error)

ChannelWebhooks returns all webhooks for a given channel. channelID: The ID of a channel.

func (*Session) Close

func (s *Session) Close() (err error)

Close closes a websocket and stops all listening/heartbeat goroutines. TODO: Add support for Voice WS/UDP connections

func (*Session) FetchChannel added in v0.20.15

func (s *Session) FetchChannel(channelID string) (st *Channel, err error)

FetchChannel returns a Channel structure of a specific Channel using the discord api. channelID : The ID of the Channel you want returned.

func (*Session) FetchGuildMember added in v0.20.15

func (s *Session) FetchGuildMember(guildID, userID string) (st *Member, err error)

FetchGuildMember returns a member of a guild from the discord api.

guildID   : The ID of a Guild.
userID    : The ID of a User

func (*Session) FetchUser added in v0.20.15

func (s *Session) FetchUser(userID string) (st *User, err error)

FetchUser returns the user details of the given userID from the discord api userID : A user ID or "@me" which is a shortcut of current user ID

func (*Session) Gateway

func (s *Session) Gateway() (gateway string, err error)

Gateway returns the websocket Gateway address

func (*Session) GatewayBot added in v0.17.0

func (s *Session) GatewayBot() (st *GatewayBotResponse, err error)

GatewayBot returns the websocket Gateway address and the recommended number of shards

func (*Session) Guild

func (s *Session) Guild(guildID string) (st *Guild, err error)

Guild returns a Guild structure of a specific Guild. guildID : The ID of a Guild

func (*Session) GuildAuditLog added in v0.20.0

func (s *Session) GuildAuditLog(guildID, userID, beforeID string, actionType, limit int) (st *GuildAuditLog, err error)

GuildAuditLog returns the audit log for a Guild. guildID : The ID of a Guild. userID : If provided the log will be filtered for the given ID. beforeID : If provided all log entries returned will be before the given ID. actionType : If provided the log will be filtered for the given Action Type. limit : The number messages that can be returned. (default 50, min 1, max 100)

func (*Session) GuildBan added in v0.20.13

func (s *Session) GuildBan(guildID string, userID string) (st *GuildBan, err error)

GuildBan returns the GuildBan structure of the banned user in the given guild guildID : The ID of a Guild. userID : The ID of a User

func (*Session) GuildBanCreate added in v0.7.0

func (s *Session) GuildBanCreate(guildID, userID string, days int) (err error)

GuildBanCreate bans the given user from the given guild. guildID : The ID of a Guild. userID : The ID of a User days : The number of days of previous comments to delete.

func (*Session) GuildBanCreateWithReason added in v0.16.0

func (s *Session) GuildBanCreateWithReason(guildID, userID, reason string, days int) (err error)

GuildBanCreateWithReason bans the given user from the given guild also providing a reason. guildID : The ID of a Guild. userID : The ID of a User reason : The reason for this ban days : The number of days of previous comments to delete.

func (*Session) GuildBanDelete

func (s *Session) GuildBanDelete(guildID, userID string) (err error)

GuildBanDelete removes the given user from the guild bans guildID : The ID of a Guild. userID : The ID of a User

func (*Session) GuildBans

func (s *Session) GuildBans(guildID string) (st []*GuildBan, err error)

GuildBans returns an array of GuildBan structures for all bans of a given guild. guildID : The ID of a Guild.

func (*Session) GuildChannelCreate

func (s *Session) GuildChannelCreate(guildID, name string, ctype ChannelType) (st *Channel, err error)

GuildChannelCreate creates a new channel in the given guild guildID : The ID of a Guild. name : Name of the channel (2-100 chars length) ctype : Type of the channel

func (*Session) GuildChannelCreateComplex added in v0.20.0

func (s *Session) GuildChannelCreateComplex(guildID string, data GuildChannelCreateData) (st *Channel, err error)

GuildChannelCreateComplex creates a new channel in the given guild guildID : The ID of a Guild data : A data struct describing the new Channel, Name and Type are mandatory, other fields depending on the type

func (*Session) GuildChannels

func (s *Session) GuildChannels(guildID string) (st []*Channel, err error)

GuildChannels returns an array of Channel structures for all channels of a given guild. guildID : The ID of a Guild.

func (*Session) GuildChannelsReorder added in v0.13.0

func (s *Session) GuildChannelsReorder(guildID string, channels []*Channel) (err error)

GuildChannelsReorder updates the order of channels in a guild guildID : The ID of a Guild. channels : Updated channels.

func (*Session) GuildCreate

func (s *Session) GuildCreate(name string) (st *Guild, err error)

GuildCreate creates a new Guild name : A name for the Guild (2-100 characters)

func (*Session) GuildEdit

func (s *Session) GuildEdit(guildID string, g *GuildParams) (st *Guild, err error)

GuildEdit edits a new Guild guildID : The ID of a Guild g : A GuildParams struct with the values Name, Region and VerificationLevel defined.

func (*Session) GuildEmbed added in v0.13.0

func (s *Session) GuildEmbed(guildID string) (st *GuildEmbed, err error)

GuildEmbed returns the embed for a Guild. guildID : The ID of a Guild.

func (*Session) GuildEmbedEdit added in v0.13.0

func (s *Session) GuildEmbedEdit(guildID string, enabled bool, channelID string) (err error)

GuildEmbedEdit returns the embed for a Guild. guildID : The ID of a Guild.

func (*Session) GuildEmojiCreate added in v0.20.0

func (s *Session) GuildEmojiCreate(guildID, name, image string, roles []string) (emoji *Emoji, err error)

GuildEmojiCreate creates a new emoji guildID : The ID of a Guild. name : The Name of the Emoji. image : The base64 encoded emoji image, has to be smaller than 256KB. roles : The roles for which this emoji will be whitelisted, can be nil.

func (*Session) GuildEmojiDelete added in v0.20.0

func (s *Session) GuildEmojiDelete(guildID, emojiID string) (err error)

GuildEmojiDelete deletes an Emoji. guildID : The ID of a Guild. emojiID : The ID of an Emoji.

func (*Session) GuildEmojiEdit added in v0.20.0

func (s *Session) GuildEmojiEdit(guildID, emojiID, name string, roles []string) (emoji *Emoji, err error)

GuildEmojiEdit modifies an emoji guildID : The ID of a Guild. emojiID : The ID of an Emoji. name : The Name of the Emoji. roles : The roles for which this emoji will be whitelisted, can be nil.

func (*Session) GuildIcon added in v0.10.0

func (s *Session) GuildIcon(guildID string) (img image.Image, err error)

GuildIcon returns an image.Image of a guild icon. guildID : The ID of a Guild.

func (*Session) GuildIntegrationCreate added in v0.13.0

func (s *Session) GuildIntegrationCreate(guildID, integrationType, integrationID string) (err error)

GuildIntegrationCreate creates a Guild Integration. guildID : The ID of a Guild. integrationType : The Integration type. integrationID : The ID of an integration.

func (*Session) GuildIntegrationDelete added in v0.13.0

func (s *Session) GuildIntegrationDelete(guildID, integrationID string) (err error)

GuildIntegrationDelete removes the given integration from the Guild. guildID : The ID of a Guild. integrationID : The ID of an integration.

func (*Session) GuildIntegrationEdit added in v0.13.0

func (s *Session) GuildIntegrationEdit(guildID, integrationID string, expireBehavior, expireGracePeriod int, enableEmoticons bool) (err error)

GuildIntegrationEdit edits a Guild Integration. guildID : The ID of a Guild. integrationType : The Integration type. integrationID : The ID of an integration. expireBehavior : The behavior when an integration subscription lapses (see the integration object documentation). expireGracePeriod : Period (in seconds) where the integration will ignore lapsed subscriptions. enableEmoticons : Whether emoticons should be synced for this integration (twitch only currently).

func (*Session) GuildIntegrationSync added in v0.13.0

func (s *Session) GuildIntegrationSync(guildID, integrationID string) (err error)

GuildIntegrationSync syncs an integration. guildID : The ID of a Guild. integrationID : The ID of an integration.

func (*Session) GuildIntegrations added in v0.13.0

func (s *Session) GuildIntegrations(guildID string) (st []*Integration, err error)

GuildIntegrations returns an array of Integrations for a guild. guildID : The ID of a Guild.

func (*Session) GuildInvites

func (s *Session) GuildInvites(guildID string) (st []*Invite, err error)

GuildInvites returns an array of Invite structures for the given guild guildID : The ID of a Guild.

func (*Session) GuildLeave added in v0.11.0

func (s *Session) GuildLeave(guildID string) (err error)

GuildLeave leaves a Guild. guildID : The ID of a Guild

func (*Session) GuildMember added in v0.11.0

func (s *Session) GuildMember(guildID, userID string) (st *Member, err error)

GuildMember returns a member of a guild. will first try the state cache before querying the discord api

guildID   : The ID of a Guild.
userID    : The ID of a User

func (*Session) GuildMemberAdd added in v0.20.0

func (s *Session) GuildMemberAdd(accessToken, guildID, userID, nick string, roles []string, mute, deaf bool) (err error)

GuildMemberAdd force joins a user to the guild.

accessToken   : Valid access_token for the user.
guildID       : The ID of a Guild.
userID        : The ID of a User.
nick          : Value to set users nickname to
roles         : A list of role ID's to set on the member.
mute          : If the user is muted.
deaf          : If the user is deafened.

func (*Session) GuildMemberDelete

func (s *Session) GuildMemberDelete(guildID, userID string) (err error)

GuildMemberDelete removes the given user from the given guild. guildID : The ID of a Guild. userID : The ID of a User

func (*Session) GuildMemberDeleteWithReason added in v0.17.0

func (s *Session) GuildMemberDeleteWithReason(guildID, userID, reason string) (err error)

GuildMemberDeleteWithReason removes the given user from the given guild. guildID : The ID of a Guild. userID : The ID of a User reason : The reason for the kick

func (*Session) GuildMemberEdit added in v0.11.0

func (s *Session) GuildMemberEdit(guildID, userID, reason string, roles []string) (err error)

GuildMemberEdit edits the roles of a member. guildID : The ID of a Guild. userID : The ID of a User. reason : The reason for the member role edit. roles : A list of role ID's to set on the member.

func (*Session) GuildMemberMove added in v0.11.0

func (s *Session) GuildMemberMove(guildID, userID, channelID, reason string) (err error)

GuildMemberMove moves a guild member from one voice channel to another

guildID   : The ID of a Guild.
userID    : The ID of a User.
channelID : The ID of a channel to move user to
reason    : The reason for the member move

func (*Session) GuildMemberNickname added in v0.13.0

func (s *Session) GuildMemberNickname(guildID, userID, nickname string) (err error)

GuildMemberNickname updates the nickname of a guild member guildID : The ID of a guild userID : The ID of a user userID : The ID of a user or "@me" which is a shortcut of the current user ID

func (*Session) GuildMemberRoleAdd added in v0.15.0

func (s *Session) GuildMemberRoleAdd(guildID, userID, roleID, reason string) (err error)

GuildMemberRoleAdd adds the specified role to a given member

guildID   : The ID of a Guild.
userID    : The ID of a User.
roleID 	  : The ID of a Role to be assigned to the user.
reason    : The reason for the role add.

func (*Session) GuildMemberRoleRemove added in v0.15.0

func (s *Session) GuildMemberRoleRemove(guildID, userID, roleID, reason string) (err error)

GuildMemberRoleRemove removes the specified role to a given member

guildID   : The ID of a Guild.
userID    : The ID of a User.
roleID 	  : The ID of a Role to be removed from the user.
reason    : The reason for the role remove.

func (*Session) GuildMemberVoiceDisconnect added in v0.20.13

func (s *Session) GuildMemberVoiceDisconnect(guildID, userID, reason string) (err error)

GuildMemberVoiceDisconnect disconnects a member from a voice channel

guildID   : The ID of a Guild.
userID    : The ID of a User.
reason    : The reason for the member move

func (*Session) GuildMembers

func (s *Session) GuildMembers(guildID string, after string, limit int) (st []*Member, err error)

GuildMembers returns a list of members for a guild.

guildID  : The ID of a Guild.
after    : The id of the member to return members after
limit    : max number of members to return (max 1000)

func (*Session) GuildPrune added in v0.15.0

func (s *Session) GuildPrune(guildID string, days uint32) (count uint32, err error)

GuildPrune Begin as prune operation. Requires the 'KICK_MEMBERS' permission. Returns an object with one 'pruned' key indicating the number of members that were removed in the prune operation. guildID : The ID of a Guild. days : The number of days to count prune for (1 or more).

func (*Session) GuildPruneCount added in v0.15.0

func (s *Session) GuildPruneCount(guildID string, days uint32) (count uint32, err error)

GuildPruneCount Returns the number of members that would be removed in a prune operation. Requires 'KICK_MEMBER' permission. guildID : The ID of a Guild. days : The number of days to count prune for (1 or more).

func (*Session) GuildRoleCreate added in v0.7.0

func (s *Session) GuildRoleCreate(guildID string, settings *RoleSettings) (st *Role, err error)

GuildRoleCreate returns a new Guild Role. guildID: The ID of a Guild.

func (*Session) GuildRoleDelete added in v0.7.0

func (s *Session) GuildRoleDelete(guildID, roleID string) (err error)

GuildRoleDelete deletes an existing role. guildID : The ID of a Guild. roleID : The ID of a Role.

func (*Session) GuildRoleEdit added in v0.7.0

func (s *Session) GuildRoleEdit(guildID, roleID, name string, color Color, hoist bool, perm Permissions, mention bool) (st *Role, err error)

GuildRoleEdit updates an existing Guild Role with new values guildID : The ID of a Guild. roleID : The ID of a Role. name : The name of the Role. color : The color of the role (decimal, not hex). hoist : Whether to display the role's users separately. perm : The permissions for the role. mention : Whether this role is mentionable

func (*Session) GuildRoleEditComplex added in v0.20.0

func (s *Session) GuildRoleEditComplex(guildID, roleID string, data *RoleSettings) (st *Role, err error)

GuildRoleEditComplex updates an existing Guild Role with new values guildID : The ID of a Guild. roleID : The ID of a Role. data : data to send to the API

func (*Session) GuildRoleReorder added in v0.7.0

func (s *Session) GuildRoleReorder(guildID string, roles []*RoleMove) (st []*Role, err error)

GuildRoleReorder reoders guild roles guildID : The ID of a Guild. roles : A list of RoleMove objects.

func (*Session) GuildRoles added in v0.7.0

func (s *Session) GuildRoles(guildID string) (st []*Role, err error)

GuildRoles returns all roles for a given guild. guildID : The ID of a Guild.

func (*Session) GuildSplash added in v0.10.0

func (s *Session) GuildSplash(guildID string) (img image.Image, err error)

GuildSplash returns an image.Image of a guild splash image. guildID : The ID of a Guild.

func (*Session) GuildWebhooks added in v0.15.0

func (s *Session) GuildWebhooks(guildID string) (st []*Webhook, err error)

GuildWebhooks returns all webhooks for a given guild. guildID: The ID of a Guild.

func (*Session) HeartbeatLatency added in v0.20.0

func (s *Session) HeartbeatLatency() time.Duration

HeartbeatLatency returns the latency between heartbeat acknowledgement and heartbeat send.

func (*Session) Invite

func (s *Session) Invite(inviteID string) (st *Invite, err error)

Invite returns an Invite structure of the given invite inviteID : The invite code

func (*Session) InviteAccept

func (s *Session) InviteAccept(inviteID string) (st *Invite, err error)

InviteAccept accepts an Invite to a Guild or Channel inviteID : The invite code

func (*Session) InviteDelete

func (s *Session) InviteDelete(inviteID string) (st *Invite, err error)

InviteDelete deletes an existing invite inviteID : the code of an invite

func (*Session) InviteWithCounts added in v0.20.0

func (s *Session) InviteWithCounts(inviteID string) (st *Invite, err error)

InviteWithCounts returns an Invite structure of the given invite including approximate member counts inviteID : The invite code

func (*Session) MessageReactionAdd added in v0.15.0

func (s *Session) MessageReactionAdd(channelID, messageID, emojiID string) error

MessageReactionAdd creates an emoji reaction to a message. channelID : The channel ID. messageID : The message ID. emojiID : Either the unicode emoji for the reaction, or a guild emoji identifier.

func (*Session) MessageReactionRemove added in v0.15.0

func (s *Session) MessageReactionRemove(channelID, messageID, emojiID, userID string) error

MessageReactionRemove deletes an emoji reaction to a message. channelID : The channel ID. messageID : The message ID. emojiID : Either the unicode emoji for the reaction, or a guild emoji identifier. userID : @me or ID of the user to delete the reaction for.

func (*Session) MessageReactions added in v0.15.0

func (s *Session) MessageReactions(channelID, messageID, emojiID string, limit int) (st []*User, err error)

MessageReactions gets all the users reactions for a specific emoji. channelID : The channel ID. messageID : The message ID. emojiID : Either the unicode emoji for the reaction, or a guild emoji identifier. limit : max number of users to return (max 100)

func (*Session) MessageReactionsRemoveAll added in v0.17.0

func (s *Session) MessageReactionsRemoveAll(channelID, messageID string) error

MessageReactionsRemoveAll deletes all reactions from a message channelID : The channel ID messageID : The message ID.

func (*Session) Open

func (s *Session) Open() error

Open creates a websocket connection to Discord. See: https://discordapp.com/developers/docs/topics/gateway#connecting

func (*Session) Request

func (s *Session) Request(method, urlStr string, data interface{}) (response []byte, err error)

Request is the same as RequestWithBucketID but the bucket id is the same as the urlStr

func (*Session) RequestGuildMembers added in v0.15.0

func (s *Session) RequestGuildMembers(guildID, query string, limit int) (err error)

RequestGuildMembers requests guild members from the gateway The gateway responds with GuildMembersChunk events guildID : The ID of the guild to request members of query : String that username starts with, leave empty to return all members limit : Max number of items to return, or 0 to request all members matched

func (*Session) RequestWithBucketID added in v0.15.0

func (s *Session) RequestWithBucketID(method, urlStr string, data interface{}, bucketID string) (response []byte, err error)

RequestWithBucketID makes a (GET/POST/...) Requests to Discord REST API with JSON data.

func (*Session) RequestWithLockedBucket added in v0.18.0

func (s *Session) RequestWithLockedBucket(method, urlStr, contentType string, b []byte, bucket *Bucket, sequence int) (response []byte, err error)

RequestWithLockedBucket makes a request using a bucket that's already been locked

func (*Session) UpdateListeningStatus added in v0.20.0

func (s *Session) UpdateListeningStatus(game string) (err error)

UpdateListeningStatus is used to set the user to "Listening to..." If game!="" then set to what user is listening to Else, set user to active and no game.

func (*Session) UpdateStatus

func (s *Session) UpdateStatus(idle int, game string) (err error)

UpdateStatus is used to update the user's status. If idle>0 then set status to idle. If game!="" then set game. if otherwise, set status to active, and no game.

func (*Session) UpdateStatusComplex added in v0.18.0

func (s *Session) UpdateStatusComplex(usd UpdateStatusData) (err error)

UpdateStatusComplex allows for sending the raw status update data untouched by discordgo.

func (*Session) UpdateStreamingStatus added in v0.13.0

func (s *Session) UpdateStreamingStatus(idle int, game string, url string) (err error)

UpdateStreamingStatus is used to update the user's streaming status. If idle>0 then set status to idle. If game!="" then set game. If game!="" and url!="" then set the status type to streaming with the URL set. if otherwise, set status to active, and no game.

func (*Session) User

func (s *Session) User(userID string) (st *User, err error)

User returns the user details of the given userID, will first try the state cache before querying the discord api userID : A user ID or "@me" which is a shortcut of current user ID

func (*Session) UserAvatarDecode added in v0.16.0

func (s *Session) UserAvatarDecode(u *User) (img image.Image, err error)

UserAvatarDecode returns an image.Image of a user's Avatar user : The user which avatar should be retrieved

func (*Session) UserChannelCreate

func (s *Session) UserChannelCreate(recipientID string) (st *Channel, err error)

UserChannelCreate creates a new User (Private) Channel with another User recipientID : A user ID for the user to which this channel is opened with.

func (*Session) UserChannels

func (s *Session) UserChannels() (st []*Channel, err error)

UserChannels returns an array of Channel structures for all private channels.

func (*Session) UserGuilds

func (s *Session) UserGuilds(limit int, beforeID, afterID string) (st []*UserGuild, err error)

UserGuilds returns an array of UserGuild structures for all guilds. limit : The number guilds that can be returned. (max 100) beforeID : If provided all guilds returned will be before given ID. afterID : If provided all guilds returned will be after given ID.

func (*Session) UserUpdate added in v0.6.0

func (s *Session) UserUpdate(username, avatar string) (st *User, err error)

UserUpdate updates a users settings.

func (*Session) UserUpdateStatus added in v0.15.0

func (s *Session) UserUpdateStatus(status Status) (err error)

UserUpdateStatus update the user status status : The new status (Actual valid status are 'online','idle','dnd','invisible')

func (*Session) VoiceICE

func (s *Session) VoiceICE() (st *VoiceICE, err error)

VoiceICE returns the voice server ICE information

func (*Session) VoiceRegions

func (s *Session) VoiceRegions() (st []*VoiceRegion, err error)

VoiceRegions returns the voice server regions

func (*Session) Webhook added in v0.15.0

func (s *Session) Webhook(webhookID string) (st *Webhook, err error)

Webhook returns a webhook for a given ID webhookID: The ID of a webhook.

func (*Session) WebhookCreate added in v0.15.0

func (s *Session) WebhookCreate(channelID, name, avatar string) (st *Webhook, err error)

WebhookCreate returns a new Webhook. channelID: The ID of a Channel. name : The name of the webhook. avatar : The avatar of the webhook.

func (*Session) WebhookDelete added in v0.15.0

func (s *Session) WebhookDelete(webhookID string) (err error)

WebhookDelete deletes a webhook for a given ID webhookID: The ID of a webhook.

func (*Session) WebhookDeleteWithToken added in v0.15.0

func (s *Session) WebhookDeleteWithToken(webhookID, token string) (err error)

WebhookDeleteWithToken deletes a webhook for a given ID with an auth token. webhookID: The ID of a webhook. token : The auth token for the webhook.

func (*Session) WebhookEdit added in v0.15.0

func (s *Session) WebhookEdit(webhookID, name, avatar, channelID string) (st *Webhook, err error)

WebhookEdit updates an existing Webhook. webhookID: The ID of a webhook. name : The name of the webhook. avatar : The avatar of the webhook.

func (*Session) WebhookEditWithToken added in v0.15.0

func (s *Session) WebhookEditWithToken(webhookID, token, name, avatar string) (st *Webhook, err error)

WebhookEditWithToken updates an existing Webhook with an auth token. webhookID: The ID of a webhook. token : The auth token for the webhook. name : The name of the webhook. avatar : The avatar of the webhook.

func (*Session) WebhookExecute added in v0.15.0

func (s *Session) WebhookExecute(webhookID, token string, wait bool, data *WebhookParams) (st *Message, err error)

WebhookExecute executes a webhook. webhookID: The ID of a webhook. token : The auth token for the webhook wait : Waits for server confirmation of message send and ensures that the return struct is populated (it is nil otherwise)

func (*Session) WebhookWithToken added in v0.15.0

func (s *Session) WebhookWithToken(webhookID, token string) (st *Webhook, err error)

WebhookWithToken returns a webhook for a given ID webhookID: The ID of a webhook. token : The auth token for the webhook.

type State added in v0.8.0

type State struct {
	sync.RWMutex
	Ready

	// MaxMessageCount represents how many messages per channel the state will store.
	MaxMessageCount int
	TrackChannels   bool
	TrackEmojis     bool
	TrackMembers    bool
	TrackRoles      bool
	TrackVoice      bool
	TrackPresences  bool
	// contains filtered or unexported fields
}

A State contains the current known state. As discord sends this in a READY blob, it seems reasonable to simply use that struct as the data store.

func NewState added in v0.8.0

func NewState() *State

NewState creates an empty state.

func (*State) Channel added in v0.8.0

func (s *State) Channel(channelID string) (*Channel, error)

Channel gets a channel by ID, it will look in all guilds and private channels.

func (*State) ChannelAdd added in v0.8.0

func (s *State) ChannelAdd(channel *Channel) error

ChannelAdd adds a channel to the current world state, or updates it if it already exists. Channels may exist either as PrivateChannels or inside a guild.

func (*State) ChannelRemove added in v0.8.0

func (s *State) ChannelRemove(channel *Channel) error

ChannelRemove removes a channel from current world state.

func (*State) Emoji added in v0.8.0

func (s *State) Emoji(guildID, emojiID string) (*Emoji, error)

Emoji returns an emoji for a guild and emoji id.

func (*State) EmojiAdd added in v0.8.0

func (s *State) EmojiAdd(guildID string, emoji *Emoji) error

EmojiAdd adds an emoji to the current world state.

func (*State) EmojisAdd added in v0.8.0

func (s *State) EmojisAdd(guildID string, emojis []*Emoji) error

EmojisAdd adds multiple emojis to the world state.

func (*State) GetUser added in v0.20.5

func (s *State) GetUser(userID string) (*User, error)

GetUser retrieves a user from the cache by ID

func (*State) Guild added in v0.8.0

func (s *State) Guild(guildID string) (*Guild, error)

Guild gets a guild by ID. Useful for querying if @me is in a guild:

_, err := discordgo.Session.State.Guild(guildID)
isInGuild := err == nil

func (*State) GuildAdd added in v0.8.0

func (s *State) GuildAdd(guild *Guild, se *Session) error

GuildAdd adds a guild to the current world state, or updates it if it already exists.

func (*State) GuildChannel added in v0.8.0

func (s *State) GuildChannel(guildID, channelID string) (*Channel, error)

GuildChannel gets a channel by ID from a guild. This method is Deprecated, use Channel(channelID)

func (*State) GuildRemove added in v0.8.0

func (s *State) GuildRemove(guild *Guild) error

GuildRemove removes a guild from current world state.

func (*State) Member added in v0.8.0

func (s *State) Member(guildID, userID string) (*Member, error)

Member gets a member by ID from a guild.

func (*State) MemberAdd added in v0.8.0

func (s *State) MemberAdd(member *Member, se *Session) error

MemberAdd adds a member to the current world state, or updates it if it already exists.

func (*State) MemberRemove added in v0.8.0

func (s *State) MemberRemove(member *Member) error

MemberRemove removes a member from current world state.

func (*State) Message added in v0.10.0

func (s *State) Message(channelID, messageID string) (*Message, error)

Message gets a message by channel and message ID.

func (*State) MessageAdd added in v0.10.0

func (s *State) MessageAdd(message *Message, se *Session) error

MessageAdd adds a message to the current world state, or updates it if it exists. If the channel cannot be found, the message is discarded. Messages are kept in state up to s.MaxMessageCount per channel.

func (*State) MessageRemove added in v0.10.0

func (s *State) MessageRemove(message *Message) error

MessageRemove removes a message from the world state.

func (*State) MyUser added in v0.20.29

func (s *State) MyUser() *User

MyUser returns the bots user

func (*State) OnInterface added in v0.17.0

func (s *State) OnInterface(se *Session, i interface{}) (err error)

OnInterface handles all events related to states.

func (*State) Presence added in v0.16.0

func (s *State) Presence(guildID, userID string) (*Presence, error)

Presence gets a presence by ID from a guild.

func (*State) PresenceAdd added in v0.16.0

func (s *State) PresenceAdd(guildID string, presence *Presence) error

PresenceAdd adds a presence to the current world state, or updates it if it already exists.

func (*State) PresenceRemove added in v0.16.0

func (s *State) PresenceRemove(guildID string, presence *Presence) error

PresenceRemove removes a presence from the current world state.

func (*State) PrivateChannel added in v0.8.0

func (s *State) PrivateChannel(channelID string) (*Channel, error)

PrivateChannel gets a private channel by ID. This method is Deprecated, use Channel(channelID)

func (*State) Role added in v0.13.0

func (s *State) Role(guildID, roleID string) (*Role, error)

Role gets a role by ID from a guild.

func (*State) RoleAdd added in v0.13.0

func (s *State) RoleAdd(guildID string, role *Role) error

RoleAdd adds a role to the current world state, or updates it if it already exists.

func (*State) RoleRemove added in v0.13.0

func (s *State) RoleRemove(guildID, roleID string) error

RoleRemove removes a role from current world state by ID.

func (*State) UserColor added in v0.16.0

func (s *State) UserColor(userID, channelID string) Color

UserColor returns the color of a user in a channel. While colors are defined at a Guild level, determining for a channel is more useful in message handlers. 0 is returned in cases of error, which is the color of @everyone. userID : The ID of the user to calculate the color for. channelID : The ID of the channel to calculate the color for.

type StateCache added in v0.20.29

type StateCache interface {
	GuildAdd(*Guild, *Session) error
	GuildRemove(*Guild) error
	Guild(string) (*Guild, error)
	PresenceAdd(string, *Presence) error
	PresenceRemove(string, *Presence) error
	Presence(string, string) (*Presence, error)
	MemberAdd(*Member, *Session) error
	MemberRemove(*Member) error
	Member(string, string) (*Member, error)
	GetUser(string) (*User, error)
	MyUser() *User
	RoleAdd(string, *Role) error
	RoleRemove(string, string) error
	Role(string, string) (*Role, error)
	ChannelAdd(*Channel) error
	ChannelRemove(*Channel) error
	Channel(string) (*Channel, error)
	Emoji(string, string) (*Emoji, error)
	EmojiAdd(string, *Emoji) error
	EmojisAdd(string, []*Emoji) error
	MessageAdd(*Message, *Session) error
	MessageRemove(*Message) error
	Message(string, string) (*Message, error)
	OnInterface(*Session, interface{}) error
	UserColor(string, string) Color
}

StateCache represents a generic state cache

type Status added in v0.15.0

type Status string

Status type definition

const (
	StatusOnline       Status = "online"
	StatusIdle         Status = "idle"
	StatusDoNotDisturb Status = "dnd"
	StatusInvisible    Status = "invisible"
	StatusOffline      Status = "offline"
)

Constants for Status with the different current available status

type TimeSortable added in v0.20.15

type TimeSortable interface {
	CreatedAt() (creation time.Time, err error)
}

TimeSortable objects are objects which can return their creation time and thus can be sorted on when they were created

type TimeSorter added in v0.20.15

type TimeSorter []TimeSortable

TimeSorter is a struct for allowing sorting on objects with a CreatedAt method

func (TimeSorter) Len added in v0.20.15

func (t TimeSorter) Len() int

func (TimeSorter) Less added in v0.20.15

func (t TimeSorter) Less(i, j int) bool

func (TimeSorter) Swap added in v0.20.15

func (t TimeSorter) Swap(i, j int)

type TimeStamps added in v0.18.0

type TimeStamps struct {
	EndTimestamp   int64 `json:"end,omitempty"`
	StartTimestamp int64 `json:"start,omitempty"`
}

A TimeStamps struct contains start and end times used in the rich presence "playing .." Game

func (*TimeStamps) UnmarshalJSON added in v0.18.0

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

UnmarshalJSON unmarshals JSON into TimeStamps struct

type Timestamp added in v0.15.0

type Timestamp string

Timestamp stores a timestamp, as sent by the Discord API.

func (Timestamp) Parse added in v0.15.0

func (t Timestamp) Parse() (time.Time, error)

Parse parses a timestamp string into a time.Time object. The only time this can fail is if Discord changes their timestamp format.

type TooManyRequests added in v0.13.0

type TooManyRequests struct {
	Bucket     string        `json:"bucket"`
	Message    string        `json:"message"`
	RetryAfter time.Duration `json:"retry_after"`
}

A TooManyRequests struct holds information received from Discord when receiving a HTTP 429 response.

type TypingStart

type TypingStart struct {
	UserID    string `json:"user_id"`
	ChannelID string `json:"channel_id"`
	GuildID   string `json:"guild_id,omitempty"`
	Timestamp int    `json:"timestamp"`
}

TypingStart is the data for a TypingStart event.

type UpdateStatusData added in v0.18.0

type UpdateStatusData struct {
	IdleSince *int   `json:"since"`
	Game      *Game  `json:"game"`
	AFK       bool   `json:"afk"`
	Status    string `json:"status"`
}

UpdateStatusData ia provided to UpdateStatusComplex()

type User

type User struct {
	// The ID of the user.
	ID string `json:"id"`

	// The email of the user. This is only present when
	// the application possesses the email scope for the user.
	Email string `json:"email"`

	// The user's username.
	Username string `json:"username"`

	// The hash of the user's avatar. Use Session.UserAvatar
	// to retrieve the avatar itself.
	Avatar string `json:"avatar"`

	// The user's chosen language option.
	Locale string `json:"locale"`

	// The discriminator of the user (4 numbers after name).
	Discriminator string `json:"discriminator"`

	// The token of the user. This is only present for
	// the user represented by the current session.
	Token string `json:"token"`

	// Whether the user's email is verified.
	Verified bool `json:"verified"`

	// Whether the user has multi-factor authentication enabled.
	MFAEnabled bool `json:"mfa_enabled"`

	// Whether the user is a bot.
	Bot bool `json:"bot"`

	// dm channel with the user, call CreateDM if it doesn't exist
	DMChannel *Channel `json:"dm_channel,omitempty"`

	// the flags on an user's account (the badges)
	Flags int `json:"flags"` // TODO: make commands to parse this

	// which nitro type the user has
	PremiumType PremiumType `json:"premium_type"`

	// The Session to call the API and retrieve other objects
	Session *Session `json:"-"`
	// contains filtered or unexported fields
}

A User stores all data for an individual Discord user.

func (*User) AvatarURL added in v0.17.0

func (u *User) AvatarURL(size string) string

AvatarURL returns a URL to the user's avatar.

size:    The size of the user's avatar as a power of two
         if size is an empty string, no size parameter will
         be added to the URL.

func (*User) CreateDM added in v0.20.0

func (u *User) CreateDM() (err error)

CreateDM creates a DM channel between the client and the user, populating User.DMChannel with it. This should usually not be called as it already gets done for you when sending or editing messages

func (User) CreatedAt added in v0.20.0

func (u User) CreatedAt() (creation time.Time, err error)

CreatedAt returns the users creation time in UTC

func (User) EditMessage added in v0.20.0

func (u User) EditMessage(data *MessageEdit) (edited *Message, err error)

EditMessage edits an existing message, replacing it entirely with the given MessageEdit struct

func (User) FetchMessage added in v0.20.0

func (u User) FetchMessage(id string) (message *Message, err error)

FetchMessage fetches a message with the given ID from the channel ID : ID of the message to fetch

func (User) GetHistory added in v0.20.0

func (u User) GetHistory(limit int, beforeID, afterID, aroundID string) (st []*Message, err error)

GetHistory fetches up to limit messages from the user limit : The number messages that can be returned. (max 100) beforeID : If provided all messages returned will be before given ID. afterID : If provided all messages returned will be after given ID. aroundID : If provided all messages returned will be around given ID.

func (User) GetHistoryIterator added in v0.20.15

func (u User) GetHistoryIterator() *HistoryIterator

GetHistoryIterator returns a bare HistoryIterator for this user.

func (User) GetID added in v0.20.0

func (u User) GetID() string

GetID returns the users ID

func (*User) IsAvatarAnimated added in v0.20.0

func (u *User) IsAvatarAnimated() bool

IsAvatarAnimated indicates if the user has an animated avatar

func (*User) IsBugHunter added in v0.20.16

func (u *User) IsBugHunter() bool

IsBugHunter returns true if the user is a Bug Hunter

func (*User) IsDiscordEmployee added in v0.20.16

func (u *User) IsDiscordEmployee() bool

IsDiscordEmployee returns true if the user is a discord employee

func (*User) IsDiscordPartner added in v0.20.16

func (u *User) IsDiscordPartner() bool

IsDiscordPartner returns true if the user is a discord partner

func (*User) IsEarlySupporter added in v0.20.16

func (u *User) IsEarlySupporter() bool

IsEarlySupporter returns true if the user is an Early Supporter

func (*User) IsHouseBalance added in v0.20.16

func (u *User) IsHouseBalance() bool

IsHouseBalance returns true if the user is part of House Balance

func (*User) IsHouseBravery added in v0.20.16

func (u *User) IsHouseBravery() bool

IsHouseBravery returns true if the user is part of House Bravery

func (*User) IsHouseBrilliance added in v0.20.16

func (u *User) IsHouseBrilliance() bool

IsHouseBrilliance returns true if the user is part of House Brilliance

func (*User) IsHypeSquadEvents added in v0.20.16

func (u *User) IsHypeSquadEvents() bool

IsHypeSquadEvents returns true if the user is part of HypeSquad Events

func (*User) IsMentionedIn added in v0.20.0

func (u *User) IsMentionedIn(message *Message) bool

IsMentionedIn checks if the user is mentioned in the given message message : message to check for mentions

func (*User) IsTeamUser added in v0.20.16

func (u *User) IsTeamUser() bool

IsTeamUser returns true if the user is part of Team User

func (User) Mention added in v0.16.0

func (u User) Mention() string

Mention return a string which mentions the user

func (User) SendMessage added in v0.20.0

func (u User) SendMessage(content string, embed *MessageEmbed, files []*File) (message *Message, err error)

SendMessage sends a message to the user content : message content to send if provided embed : embed to attach to the message if provided files : files to attach to the message if provided

func (User) SendMessageComplex added in v0.20.0

func (u User) SendMessageComplex(data *MessageSend) (message *Message, err error)

SendMessageComplex sends a message to the user data : MessageSend object with the data to send

func (User) String added in v0.16.0

func (u User) String() string

String returns a unique identifier of the form username#discriminator

type UserGuild added in v0.15.0

type UserGuild struct {
	ID          string `json:"id"`
	Name        string `json:"name"`
	Icon        string `json:"icon"`
	Owner       bool   `json:"owner"`
	Permissions int    `json:"permissions"`
}

A UserGuild holds a brief version of a Guild

type UserNoteUpdate added in v0.16.0

type UserNoteUpdate struct {
	ID   string `json:"id"`
	Note string `json:"note"`
}

UserNoteUpdate is the data for a UserNoteUpdate event.

type UserUpdate added in v0.11.0

type UserUpdate struct {
	*User
	BeforeUpdate *User `json:"-"`
}

UserUpdate is the data for a UserUpdate event.

type VerificationLevel added in v0.12.0

type VerificationLevel int

VerificationLevel type definition

const (
	VerificationLevelNone VerificationLevel = iota
	VerificationLevelLow
	VerificationLevelMedium
	VerificationLevelHigh
	VerificationLevelVeryHigh
)

Constants for VerificationLevel levels from 0 to 4 inclusive

type VoiceConnection added in v0.12.0

type VoiceConnection struct {
	sync.RWMutex

	Debug     bool // If true, print extra logging -- DEPRECATED
	LogLevel  int
	Ready     bool // If true, voice is ready to send/receive audio
	UserID    string
	GuildID   string
	ChannelID string

	OpusSend chan []byte  // Chan for sending opus audio
	OpusRecv chan *Packet // Chan for receiving opus audio
	// contains filtered or unexported fields
}

A VoiceConnection struct holds all the data and functions related to a Discord Voice Connection.

func (*VoiceConnection) AddHandler added in v0.12.0

AddHandler adds a Handler for VoiceSpeakingUpdate events.

func (*VoiceConnection) ChangeChannel added in v0.12.0

func (v *VoiceConnection) ChangeChannel(channelID string, mute, deaf bool) (err error)

ChangeChannel sends Discord a request to change channels within a Guild !!! NOTE !!! This function may be removed in favour of just using ChannelVoiceJoin

func (*VoiceConnection) Close added in v0.12.0

func (v *VoiceConnection) Close()

Close closes the voice ws and udp connections

func (*VoiceConnection) Disconnect added in v0.12.0

func (v *VoiceConnection) Disconnect() (err error)

Disconnect disconnects from this voice channel and closes the websocket and udp connections to Discord.

func (*VoiceConnection) Speaking added in v0.12.0

func (v *VoiceConnection) Speaking(b bool) (err error)

Speaking sends a speaking notification to Discord over the voice websocket. This must be sent as true prior to sending audio and should be set to false once finished sending audio.

b  : Send true if speaking, false if not.

type VoiceICE

type VoiceICE struct {
	TTL     string       `json:"ttl"`
	Servers []*ICEServer `json:"servers"`
}

A VoiceICE stores data for voice ICE servers.

type VoiceRegion

type VoiceRegion struct {
	ID       string `json:"id"`
	Name     string `json:"name"`
	Hostname string `json:"sample_hostname"`
	Port     int    `json:"sample_port"`
}

A VoiceRegion stores data for a specific voice region server.

type VoiceServerUpdate

type VoiceServerUpdate struct {
	Token    string `json:"token"`
	GuildID  string `json:"guild_id"`
	Endpoint string `json:"endpoint"`
}

VoiceServerUpdate is the data for a VoiceServerUpdate event.

type VoiceSpeakingUpdate added in v0.12.0

type VoiceSpeakingUpdate struct {
	UserID   string `json:"user_id"`
	SSRC     int    `json:"ssrc"`
	Speaking bool   `json:"speaking"`
}

VoiceSpeakingUpdate is a struct for a VoiceSpeakingUpdate event.

type VoiceSpeakingUpdateHandler added in v0.12.0

type VoiceSpeakingUpdateHandler func(vc *VoiceConnection, vs *VoiceSpeakingUpdate)

VoiceSpeakingUpdateHandler type provides a function definition for the VoiceSpeakingUpdate event

type VoiceState

type VoiceState struct {
	UserID    string `json:"user_id"`
	SessionID string `json:"session_id"`
	ChannelID string `json:"channel_id"`
	GuildID   string `json:"guild_id"`
	Suppress  bool   `json:"suppress"`
	SelfMute  bool   `json:"self_mute"`
	SelfDeaf  bool   `json:"self_deaf"`
	Mute      bool   `json:"mute"`
	Deaf      bool   `json:"deaf"`
}

A VoiceState stores the voice states of Guilds

type VoiceStateUpdate added in v0.11.0

type VoiceStateUpdate struct {
	*VoiceState
	BeforeUpdate *VoiceState `json:"-"`
}

VoiceStateUpdate is the data for a VoiceStateUpdate event.

type Webhook added in v0.15.0

type Webhook struct {
	ID        string `json:"id"`
	Type      int    `json:"type"`
	GuildID   string `json:"guild_id"`
	ChannelID string `json:"channel_id"`
	User      *User  `json:"user"`
	Name      string `json:"name"`
	Avatar    string `json:"avatar"`
	Token     string `json:"token"`
}

Webhook stores the data for a webhook.

type WebhookParams added in v0.15.0

type WebhookParams struct {
	Content   string          `json:"content,omitempty"`
	Username  string          `json:"username,omitempty"`
	AvatarURL string          `json:"avatar_url,omitempty"`
	TTS       bool            `json:"tts,omitempty"`
	File      string          `json:"file,omitempty"`
	Embeds    []*MessageEmbed `json:"embeds,omitempty"`
}

WebhookParams is a struct for webhook params, used in the WebhookExecute command.

type WebhooksUpdate added in v0.20.0

type WebhooksUpdate struct {
	GuildID   string `json:"guild_id"`
	ChannelID string `json:"channel_id"`
}

WebhooksUpdate is the data for a WebhooksUpdate event

Directories

Path Synopsis
examples
tools

Jump to

Keyboard shortcuts

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