discordgo

package module
Version: v0.13.0 Latest Latest
Warning

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

Go to latest
Published: Jul 18, 2016 License: BSD-3-Clause Imports: 25 Imported by: 0

README

DiscordGo ==== [![GoDoc](https://godoc.org/github.com/bwmarrin/discordgo?status.svg)](https://godoc.org/github.com/bwmarrin/discordgo) [![Go report](http://goreportcard.com/badge/bwmarrin/discordgo)](http://goreportcard.com/report/bwmarrin/discordgo) [![Build Status](https://travis-ci.org/bwmarrin/discordgo.svg?branch=master)](https://travis-ci.org/bwmarrin/discordgo) [![Discord Gophers](https://img.shields.io/badge/Discord%20Gophers-%23discordgo-blue.svg)](https://discord.gg/0f1SbxBZjYoCtNPP) [![Discord API](https://img.shields.io/badge/Discord%20API-%23go_discordgo-blue.svg)](https://discord.gg/0SBTUU1wZTWT6sqd)

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 JSON-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 to extend DiscordGo with additional voice helper functions and features.

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

Join Discord Gophers Discord chat channel for support.

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 then 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 then use master

Installing

DiscordGo has been tested to compile on Debian 8 (Go 1.3.3), FreeBSD 10 (Go 1.5.1), and Windows 7 (Go 1.5.2).

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("username", "password")

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 functions, constants, and structures.

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.

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

Examples

Constants

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 returend 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 = 1 << (iota + 10)
	PermissionSendMessages
	PermissionSendTTSMessages
	PermissionManageMessages
	PermissionEmbedLinks
	PermissionAttachFiles
	PermissionReadMessageHistory
	PermissionMentionEveryone
)

Constants for the different bit offsets of text channel permissions

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

Constants for the different bit offsets of voice permissions

Constants for the different bit offsets of general permissions

View Source
const VERSION = "0.13.0"

VERSION of Discordgo, follows Symantic 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/"
	EndpointGuilds   = EndpointAPI + "guilds/"
	EndpointChannels = EndpointAPI + "channels/"
	EndpointUsers    = EndpointAPI + "users/"
	EndpointGateway  = EndpointAPI + "gateway"

	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 EndpointUsers + uID + "/avatars/" + aID + ".jpg" }
	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" }

	EndpointGuild                = func(gID string) string { return EndpointGuilds + gID }
	EndpointGuildInivtes         = func(gID string) string { return EndpointGuilds + gID + "/invites" }
	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 }
	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 EndpointGuilds + gID + "/icons/" + hash + ".jpg" }
	EndpointGuildSplash          = func(gID, hash string) string { return EndpointGuilds + gID + "/splashes/" + hash + ".jpg" }

	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 }

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

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

Known Discord API Endpoints.

View Source
var ErrJSONUnmarshal = errors.New("json unmarshal")

ErrJSONUnmarshal is returned for JSON Unmarshall errors.

View Source
var ErrNilState = errors.New("State not instantiated, please use discordgo.New() or assign Session.State.")

ErrNilState is returned when the state is nil.

Functions

This section is empty.

Types

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

An Application struct stores values for a Discord OAuth2 Application

Example
package main

import (
	"log"
	"os"

	"github.com/bwmarrin/discordgo"
)

func main() {

	// Authentication Token pulled from environment variable DG_TOKEN
	Token := os.Getenv("DG_TOKEN")
	if Token == "" {
		return
	}

	// Create a new Discordgo session
	dg, err := discordgo.New(Token)
	if err != nil {
		log.Println(err)
		return
	}

	// Create an new Application
	ap := &discordgo.Application{}
	ap.Name = "TestApp"
	ap.Description = "TestDesc"
	ap, err = dg.ApplicationCreate(ap)
	log.Printf("ApplicationCreate: err: %+v, app: %+v\n", err, ap)

	// Get a specific Application by it's ID
	ap, err = dg.Application(ap.ID)
	log.Printf("Application: err: %+v, app: %+v\n", err, ap)

	// Update an existing Application with new values
	ap.Description = "Whooooa"
	ap, err = dg.ApplicationUpdate(ap.ID, ap)
	log.Printf("ApplicationUpdate: err: %+v, app: %+v\n", err, ap)

	// create a new bot account for this application
	bot, err := dg.ApplicationBotCreate(ap.ID)
	log.Printf("BotCreate: err: %+v, bot: %+v\n", err, bot)

	// Get a list of all applications for the authenticated user
	apps, err := dg.Applications()
	log.Printf("Applications: err: %+v, apps : %+v\n", err, apps)
	for k, v := range apps {
		log.Printf("Applications: %d : %+v\n", k, v)
	}

	// Delete the application we created.
	err = dg.ApplicationDelete(ap.ID)
	log.Printf("Delete: err: %+v\n", err)

	return
}
Output:

type Channel

type Channel struct {
	ID                   string                 `json:"id"`
	GuildID              string                 `json:"guild_id"`
	Name                 string                 `json:"name"`
	Topic                string                 `json:"topic"`
	Type                 string                 `json:"type"`
	LastMessageID        string                 `json:"last_message_id"`
	Position             int                    `json:"position"`
	Bitrate              int                    `json:"bitrate"`
	IsPrivate            bool                   `json:"is_private"`
	Recipient            *User                  `json:"recipient"`
	Messages             []*Message             `json:"-"`
	PermissionOverwrites []*PermissionOverwrite `json:"permission_overwrites"`
}

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

type ChannelCreate added in v0.11.0

type ChannelCreate struct {
	*Channel
}

ChannelCreate is a wrapper struct for an event.

type ChannelDelete added in v0.11.0

type ChannelDelete struct {
	*Channel
}

ChannelDelete is a wrapper struct for an event.

type ChannelUpdate added in v0.11.0

type ChannelUpdate struct {
	*Channel
}

ChannelUpdate is a wrapper struct for an event.

type Connect added in v0.11.0

type Connect struct{}

Connect is an empty struct for an event.

type Disconnect added in v0.11.0

type Disconnect struct{}

Disconnect is an empty struct for an event.

type Emoji added in v0.8.0

type Emoji struct {
	ID            string   `json:"id"`
	Name          string   `json:"name"`
	Roles         []string `json:"roles"`
	Managed       bool     `json:"managed"`
	RequireColons bool     `json:"require_colons"`
}

Emoji struct holds data related to Emoji's

type Event

type Event struct {
	Operation int             `json:"op"`
	Sequence  int             `json:"s"`
	Type      string          `json:"t"`
	RawData   json.RawMessage `json:"d"`
	Struct    interface{}     `json:"-"`
}

An Event provides a basic initial struct for all websocket event.

type FriendSourceFlags added in v0.13.0

type FriendSourceFlags struct {
	All           bool `json:"all"`
	MutualGuilds  bool `json:"mutual_guilds"`
	MutualFriends bool `json:"mutual_friends"`
}

FriendSourceFlags stores ... TODO :)

type Game added in v0.7.0

type Game struct {
	Name string `json:"name"`
	Type int    `json:"type"`
	URL  string `json:"url"`
}

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

type Guild

type Guild struct {
	ID                          string            `json:"id"`
	Name                        string            `json:"name"`
	Icon                        string            `json:"icon"`
	Region                      string            `json:"region"`
	AfkChannelID                string            `json:"afk_channel_id"`
	EmbedChannelID              string            `json:"embed_channel_id"`
	OwnerID                     string            `json:"owner_id"`
	JoinedAt                    string            `json:"joined_at"` // make this a timestamp
	Splash                      string            `json:"splash"`
	AfkTimeout                  int               `json:"afk_timeout"`
	VerificationLevel           VerificationLevel `json:"verification_level"`
	EmbedEnabled                bool              `json:"embed_enabled"`
	Large                       bool              `json:"large"` // ??
	DefaultMessageNotifications int               `json:"default_message_notifications"`
	Roles                       []*Role           `json:"roles"`
	Emojis                      []*Emoji          `json:"emojis"`
	Members                     []*Member         `json:"members"`
	Presences                   []*Presence       `json:"presences"`
	Channels                    []*Channel        `json:"channels"`
	VoiceStates                 []*VoiceState     `json:"voice_states"`
	Unavailable                 *bool             `json:"unavailable"`
}

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

type GuildBan added in v0.8.0

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

A GuildBan stores data for a guild ban.

type GuildBanAdd added in v0.11.0

type GuildBanAdd struct {
	*GuildBan
}

GuildBanAdd is a wrapper struct for an event.

type GuildBanRemove added in v0.11.0

type GuildBanRemove struct {
	*GuildBan
}

GuildBanRemove is a wrapper struct for an event.

type GuildCreate added in v0.11.0

type GuildCreate struct {
	*Guild
}

GuildCreate is a wrapper struct for an event.

type GuildDelete added in v0.11.0

type GuildDelete struct {
	*Guild
}

GuildDelete is a wrapper struct for an 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 stores data for a guild emoji update event.

type GuildIntegration added in v0.13.0

type GuildIntegration 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           *GuildIntegrationAccount `json:"account"`
	SyncedAt          int                      `json:"synced_at"`
}

A GuildIntegration stores data for a guild integration.

type GuildIntegrationAccount added in v0.13.0

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

A GuildIntegrationAccount stores data for a guild integration account.

type GuildIntegrationsUpdate

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

A GuildIntegrationsUpdate stores data for the guild integrations update websocket event.

type GuildMemberAdd added in v0.11.0

type GuildMemberAdd struct {
	*Member
}

GuildMemberAdd is a wrapper struct for an event.

type GuildMemberRemove added in v0.11.0

type GuildMemberRemove struct {
	*Member
}

GuildMemberRemove is a wrapper struct for an event.

type GuildMemberUpdate added in v0.11.0

type GuildMemberUpdate struct {
	*Member
}

GuildMemberUpdate is a wrapper struct for an event.

type GuildParams added in v0.12.0

type GuildParams struct {
	Name              string             `json:"name"`
	Region            string             `json:"region"`
	VerificationLevel *VerificationLevel `json:"verification_level"`
}

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

type GuildRole

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

A GuildRole stores data for guild role websocket events.

type GuildRoleCreate added in v0.11.0

type GuildRoleCreate struct {
	*GuildRole
}

GuildRoleCreate is a wrapper struct for an event.

type GuildRoleDelete

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

A GuildRoleDelete stores data for the guild role delete websocket event.

type GuildRoleUpdate added in v0.11.0

type GuildRoleUpdate struct {
	*GuildRole
}

GuildRoleUpdate is a wrapper struct for an event.

type GuildUpdate added in v0.11.0

type GuildUpdate struct {
	*Guild
}

GuildUpdate is a wrapper struct for an event.

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 Invite

type Invite struct {
	Guild     *Guild   `json:"guild"`
	Channel   *Channel `json:"channel"`
	Inviter   *User    `json:"inviter"`
	Code      string   `json:"code"`
	CreatedAt string   `json:"created_at"` // TODO make timestamp
	MaxAge    int      `json:"max_age"`
	Uses      int      `json:"uses"`
	MaxUses   int      `json:"max_uses"`
	XkcdPass  string   `json:"xkcdpass"`
	Revoked   bool     `json:"revoked"`
	Temporary bool     `json:"temporary"`
}

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

type Member

type Member struct {
	GuildID  string   `json:"guild_id"`
	JoinedAt string   `json:"joined_at"`
	Nick     string   `json:"nick"`
	Deaf     bool     `json:"deaf"`
	Mute     bool     `json:"mute"`
	User     *User    `json:"user"`
	Roles    []string `json:"roles"`
}

A Member stores user information for Guild members.

type Message

type Message struct {
	ID              string               `json:"id"`
	ChannelID       string               `json:"channel_id"`
	Content         string               `json:"content"`
	Timestamp       string               `json:"timestamp"`
	EditedTimestamp string               `json:"edited_timestamp"`
	MentionRoles    []string             `json:"mention_roles"`
	Tts             bool                 `json:"tts"`
	MentionEveryone bool                 `json:"mention_everyone"`
	Author          *User                `json:"author"`
	Attachments     []*MessageAttachment `json:"attachments"`
	Embeds          []*MessageEmbed      `json:"embeds"`
	Mentions        []*User              `json:"mentions"`
}

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

func (*Message) ContentWithMentionsReplaced added in v0.8.0

func (m *Message) ContentWithMentionsReplaced() string

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

type MessageAck

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

A MessageAck stores data for the message ack websocket event.

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 a wrapper struct for an event.

type MessageDelete

type MessageDelete struct {
	*Message
}

MessageDelete is a wrapper struct for an event.

type MessageEmbed added in v0.13.0

type MessageEmbed struct {
	URL         string `json:"url"`
	Type        string `json:"type"`
	Title       string `json:"title"`
	Description string `json:"description"`
	Thumbnail   *struct {
		URL      string `json:"url"`
		ProxyURL string `json:"proxy_url"`
		Width    int    `json:"width"`
		Height   int    `json:"height"`
	} `json:"thumbnail"`
	Provider *struct {
		URL  string `json:"url"`
		Name string `json:"name"`
	} `json:"provider"`
	Author *struct {
		URL  string `json:"url"`
		Name string `json:"name"`
	} `json:"author"`
	Video *struct {
		URL    string `json:"url"`
		Width  int    `json:"width"`
		Height int    `json:"height"`
	} `json:"video"`
}

An MessageEmbed stores data for message embeds.

type MessageUpdate added in v0.11.0

type MessageUpdate struct {
	*Message
}

MessageUpdate is a wrapper struct for an event.

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 PermissionOverwrite

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

A PermissionOverwrite holds permission overwrite data for a Channel

type Presence

type Presence struct {
	User   *User  `json:"user"`
	Status string `json:"status"`
	Game   *Game  `json:"game"`
}

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

A PresenceUpdate stores data for the presence update websocket event.

type PresencesReplace added in v0.12.0

type PresencesReplace []*Presence

PresencesReplace is an array of Presences for an event.

type RateLimit added in v0.9.0

type RateLimit struct {
	*TooManyRequests
	URL string
}

RateLimit is a struct for the RateLimited event

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"`
	HeartbeatInterval time.Duration `json:"heartbeat_interval"`
	User              *User         `json:"user"`
	ReadState         []*ReadState  `json:"read_state"`
	PrivateChannels   []*Channel    `json:"private_channels"`
	Guilds            []*Guild      `json:"guilds"`

	// Undocumented fields
	Settings          *Settings            `json:"user_settings"`
	UserGuildSettings []*UserGuildSettings `json:"user_guild_settings"`
	Relationships     []*Relationship      `json:"relationships"`
	Presences         []*Presence          `json:"presences"`
}

A Ready stores all data for the websocket READY event.

type Relationship added in v0.13.0

type Relationship struct {
	User *User  `json:"user"`
	Type int    `json:"type"` // 1 = friend, 2 = blocked, 3 = incoming friend req, 4 = sent friend req
	ID   string `json:"id"`
}

A Relationship between the logged in user and Relationship.User

type Resumed added in v0.13.0

type Resumed struct {
	HeartbeatInterval time.Duration `json:"heartbeat_interval"`
	Trace             []string      `json:"_trace"`
}

A Resumed struct holds the data received in a RESUMED event

type Role

type Role struct {
	ID          string `json:"id"`
	Name        string `json:"name"`
	Managed     bool   `json:"managed"`
	Hoist       bool   `json:"hoist"`
	Color       int    `json:"color"`
	Position    int    `json:"position"`
	Permissions int    `json:"permissions"`
}

A Role stores information about Discord guild member roles.

type Session

type Session struct {
	sync.RWMutex

	// Authentication token for this session
	Token string

	// 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 the Data Websocket is ready
	DataReady bool // NOTE: Maye be deprecated soon

	// 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 *State
	// 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. There are 3 ways to call New:

With a single auth token - All requests will use the token blindly,
    no verification of the token will be done and requests may fail.
With an email and password - Discord will sign in with the provided
    credentials.
With an email, password and auth token - Discord will verify the auth
    token, if it is invalid it will sign in with the provided
    credentials. This is the Discord recommended way to sign in.

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 interface fires. eventToInterface in events.go has a list of all the Discord WSAPI events and their respective interface. eg:

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

or:

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

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

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) 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 strucutre of a specific Channel. 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) (st *Channel, err error)

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

func (*Session) ChannelFileSend added in v0.11.0

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

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

func (*Session) ChannelInviteCreate

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

ChannelInviteCreate creates a new invite for the given channel. channelID : The ID of a Channel i : An Invite struct with the values MaxAge, MaxUses, Temporary,

and XkcdPass defined.

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 string) (err error)

ChannelMessageAck acknowledges and marks the given message as read channeld : The ID of a Channel messageID : the ID of a Message

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) (st *Message, err error)

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

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) (st *Message, err error)

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

func (*Session) ChannelMessageSendTTS added in v0.11.0

func (s *Session) ChannelMessageSendTTS(channelID string, content string) (st *Message, err 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 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.

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 funciton. 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 int) (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) 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) Gateway

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

Gateway returns the a websocket Gateway address

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) 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) 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 []*User, err error)

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

func (*Session) GuildChannelCreate

func (s *Session) GuildChannelCreate(guildID, name, ctype string) (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 : Tpye of the channel (voice or text)

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

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

GuildDelete deletes a Guild. guildID : The ID of a Guild

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) 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 []*GuildIntegration, 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.

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

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) GuildMemberEdit added in v0.11.0

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

GuildMemberEdit edits the roles of a member. guildID : The ID of a Guild. userID : The ID of a User. 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 string) (err error)

GuildMemberMove moves a guild member from one voice channel to another/none

guildID   : The ID of a Guild.
userID    : The ID of a User.
channelID : The ID of a channel to move user to, or null?

NOTE : I am not entirely set on the name of this function and it may change prior to the final 1.0.0 release of Discordgo

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

func (*Session) GuildMembers

func (s *Session) GuildMembers(guildID string, offset, limit int) (st []*Member, err error)

GuildMembers returns a list of members for a guild.

guildID  : The ID of a Guild.
offset   : A number of members to skip
limit    : max number of members to return (max 1000)

func (*Session) GuildRoleCreate added in v0.7.0

func (s *Session) GuildRoleCreate(guildID string) (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 int, hoist bool, perm int) (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.

func (*Session) GuildRoleReorder added in v0.7.0

func (s *Session) GuildRoleReorder(guildID string, roles []*Role) (st []*Role, err error)

GuildRoleReorder reoders guild roles guildID : The ID of a Guild. roles : A list of ordered roles.

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

func (s *Session) Invite(inviteID string) (st *Invite, err error)

Invite returns an Invite structure of the given invite inviteID : The invite code (or maybe xkcdpass?)

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 (or maybe xkcdpass?)

func (*Session) InviteDelete

func (s *Session) InviteDelete(inviteID string) (st *Invite, err error)

InviteDelete deletes an existing invite inviteID : the code (or maybe xkcdpass?) of an invite

func (*Session) Login

func (s *Session) Login(email, password string) (err error)

Login asks the Discord server for an authentication token.

func (*Session) Logout

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

Logout sends a logout request to Discord. This does not seem to actually invalidate the token. So you can still make API calls even after a Logout. So, it seems almost pointless to even use.

func (*Session) Open

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

Open opens a websocket connection to Discord.

func (*Session) Register added in v0.9.0

func (s *Session) Register(username string) (token string, err error)

Register sends a Register request to Discord, and returns the authentication token Note that this account is temporary and should be verified for future use. Another option is to save the authentication token external, but this isn't recommended.

func (*Session) Request

func (s *Session) Request(method, urlStr string, data interface{}) (response []byte, err error)

Request makes a (GET/POST/...) Requests to Discord REST API with JSON data. All the other Discord REST Calls in this file use this function.

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) 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 userID : A user ID or "@me" which is a shortcut of current user ID

func (*Session) UserAvatar

func (s *Session) UserAvatar(userID string) (img image.Image, err error)

UserAvatar returns an image.Image of a users Avatar. userID : A user ID or "@me" which is a shortcut of current user ID

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) UserChannelPermissions added in v0.12.0

func (s *Session) UserChannelPermissions(userID, channelID string) (apermissions int, err error)

NOTE: This function is now deprecated and will be removed in the future. Please see the same function inside state.go UserChannelPermissions returns the permission of a user in a channel. userID : The ID of the user to calculate permissions for. channelID : The ID of the channel to calculate permission for.

func (*Session) UserChannels

func (s *Session) UserChannels() (st []*Channel, err error)

UserChannels returns an array of Channel structures for all private channels.

func (*Session) UserGuildSettingsEdit added in v0.13.0

func (s *Session) UserGuildSettingsEdit(guildID string, settings *UserGuildSettingsEdit) (st *UserGuildSettings, err error)

UserGuildSettingsEdit Edits the users notification settings for a guild guildID : The ID of the guild to edit the settings on settings : The settings to update

func (*Session) UserGuilds

func (s *Session) UserGuilds() (st []*Guild, err error)

UserGuilds returns an array of Guild structures for all guilds.

func (*Session) UserSettings

func (s *Session) UserSettings() (st *Settings, err error)

UserSettings returns the settings for a given user

func (*Session) UserUpdate added in v0.6.0

func (s *Session) UserUpdate(email, password, username, avatar, newPassword string) (st *User, err error)

UserUpdate updates a users settings.

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

type Settings

type Settings struct {
	RenderEmbeds            bool               `json:"render_embeds"`
	InlineEmbedMedia        bool               `json:"inline_embed_media"`
	InlineAttachmentMedia   bool               `json:"inline_attachment_media"`
	EnableTtsCommand        bool               `json:"enable_tts_command"`
	MessageDisplayCompact   bool               `json:"message_display_compact"`
	ShowCurrentGame         bool               `json:"show_current_game"`
	AllowEmailFriendRequest bool               `json:"allow_email_friend_request"`
	ConvertEmoticons        bool               `json:"convert_emoticons"`
	Locale                  string             `json:"locale"`
	Theme                   string             `json:"theme"`
	GuildPositions          []string           `json:"guild_positions"`
	RestrictedGuilds        []string           `json:"restricted_guilds"`
	FriendSourceFlags       *FriendSourceFlags `json:"friend_source_flags"`
}

A Settings stores data for a specific users Discord client settings.

type State added in v0.8.0

type State struct {
	sync.RWMutex
	Ready

	MaxMessageCount int
	TrackChannels   bool
	TrackEmojis     bool
	TrackMembers    bool
	TrackRoles      bool
	TrackVoice      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 an private channels.

func (*State) ChannelAdd added in v0.8.0

func (s *State) ChannelAdd(channel *Channel) error

ChannelAdd adds a guild 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) 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) 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) 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) 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

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) OnReady added in v0.8.0

func (s *State) OnReady(r *Ready) error

OnReady takes a Ready event and updates all internal 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) UserChannelPermissions added in v0.13.0

func (s *State) UserChannelPermissions(userID, channelID string) (apermissions int, err error)

UserChannelPermissions returns the permission of a user in a channel. userID : The ID of the user to calculate permissions for. channelID : The ID of the channel to calculate permission for.

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"`
	Timestamp int    `json:"timestamp"`
}

A TypingStart stores data for the typing start websocket event.

type User

type User struct {
	ID            string `json:"id"`
	Email         string `json:"email"`
	Username      string `json:"username"`
	Avatar        string `json:"Avatar"`
	Discriminator string `json:"discriminator"`
	Token         string `json:"token"`
	Verified      bool   `json:"verified"`
	MFAEnabled    bool   `json:"mfa_enabled"`
	Bot           bool   `json:"bot"`
}

A User stores all data for an individual Discord user.

type UserGuildSettings added in v0.12.0

type UserGuildSettings struct {
	SupressEveryone      bool                                `json:"suppress_everyone"`
	Muted                bool                                `json:"muted"`
	MobilePush           bool                                `json:"mobile_push"`
	MessageNotifications int                                 `json:"message_notifications"`
	GuildID              string                              `json:"guild_id"`
	ChannelOverrides     []*UserGuildSettingsChannelOverride `json:"channel_overrides"`
}

A UserGuildSettings stores data for a users guild settings.

type UserGuildSettingsChannelOverride added in v0.12.0

type UserGuildSettingsChannelOverride struct {
	Muted                bool   `json:"muted"`
	MessageNotifications int    `json:"message_notifications"`
	ChannelID            string `json:"channel_id"`
}

A UserGuildSettingsChannelOverride stores data for a channel override for a users guild settings.

type UserGuildSettingsEdit added in v0.13.0

type UserGuildSettingsEdit struct {
	SupressEveryone      bool                                         `json:"suppress_everyone"`
	Muted                bool                                         `json:"muted"`
	MobilePush           bool                                         `json:"mobile_push"`
	MessageNotifications int                                          `json:"message_notifications"`
	ChannelOverrides     map[string]*UserGuildSettingsChannelOverride `json:"channel_overrides"`
}

A UserGuildSettingsEdit stores data for editing UserGuildSettings

type UserGuildSettingsUpdate added in v0.12.0

type UserGuildSettingsUpdate struct {
	*UserGuildSettings
}

UserGuildSettingsUpdate is a map for an event.

type UserSettingsUpdate added in v0.11.0

type UserSettingsUpdate map[string]interface{}

UserSettingsUpdate is a map for an event.

type UserUpdate added in v0.11.0

type UserUpdate struct {
	*User
}

UserUpdate is a wrapper struct for an event.

type VerificationLevel added in v0.12.0

type VerificationLevel int

VerificationLevel type defination

const (
	VerificationLevelNone VerificationLevel = iota
	VerificationLevelLow
	VerificationLevelMedium
	VerificationLevelHigh
)

Constants for VerificationLevel levels from 0 to 3 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. !!! NOTE !!! this function may be removed in favour of ChannelVoiceLeave

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

A VoiceServerUpdate stores the data received during the Voice Server Update data websocket event. This data is used during the initial Voice Channel join handshaking.

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 defination 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
}

VoiceStateUpdate is a wrapper struct for an event.

Directories

Path Synopsis
examples

Jump to

Keyboard shortcuts

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