discordgo

package module
v0.7.0 Latest Latest
Warning

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

Go to latest
Published: Dec 29, 2015 License: BSD-3-Clause Imports: 13 Imported by: 0

README

DiscordGo provides low level bindings for Discord in the Go Programming Language (Golang).

  • See dgVoice for experimental voice support.

Join #go_discordgo Discord API channel on Discord for support.

GoDoc Go Walker Go report Build Status


Usage Examples

See the example sub-folder for examples. Each example accepts a username and password as a CLI argument when run.

Documentation

NOTICE : This library and the Discord API are unfinished. Because of that there may be major changes to library functions, constants, and structures.

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

What Works

Current package provides a low level direct mapping to the majority of Discord REST and Websock API.

  • Login/Logout
  • Open/Close Websocket and listen for events.
  • Accept/Create/Delete Invites
  • Get User details (Name, ID, Settings, etc)
  • List/Create User Channels (Private Message Channels)
  • List/Create Guilds
  • List/Create Guild Channels
  • List Guild Members
  • Receive/Send Messages to Channels

What's Unfinished

  • Make changes as needed to pass GoLint, GoVet, GoCyclo, etc. (goreportcard.com)
  • Editing User Profile settings
  • Permissions related functions.
  • Functions for Maintenance Status
  • Finish Voice support.
  • Add a higher level interface with user friendly helper functions.

Other Discord APIs

Go: gdraynz/go-discord, Xackery/discord, Nerketur/discordapi

.NET: RogueException/Discord.Net, Luigifan/DiscordSharp

Java: nerd/Discord4J

Node.js: izy521/discord.io, hydrabolt/discord.js, qeled/discordie,

PHP: Cleanse/discord-hypertext, teamreflex/DiscordPHP

Python: Rapptz/discord.py

Ruby: meew0/discordrb

Scala: eaceaser/discord-akka

Rust: SpaceManiac/discord-rs

Documentation

Overview

package discordgo provides Discord binding for Go

Index

Constants

View Source
const VERSION = "0.7.0"

DiscordGo Version, follows Symantic Versioning. (http://semver.org/)

Variables

View Source
var (
	STATUS      = "https://status.discordapp.com/api/v2/"
	SM          = STATUS + "scheduled-maintenances/"
	SM_ACTIVE   = SM + "active.json"
	SM_UPCOMING = SM + "upcoming.json"

	DISCORD  = "https://discordapp.com" // TODO consider removing
	API      = DISCORD + "/api/"
	GUILDS   = API + "guilds/"
	CHANNELS = API + "channels/"
	USERS    = API + "users/"
	GATEWAY  = API + "gateway"

	AUTH            = API + "auth/"
	LOGIN           = AUTH + "login"
	LOGOUT          = AUTH + "logout"
	VERIFY          = AUTH + "verify"
	VERIFY_RESEND   = AUTH + "verify/resend"
	FORGOT_PASSWORD = AUTH + "forgot"
	RESET_PASSWORD  = AUTH + "reset"
	REGISTER        = AUTH + "register"

	VOICE         = API + "/voice/"
	VOICE_REGIONS = VOICE + "regions"
	VOICE_ICE     = VOICE + "ice"

	TUTORIAL            = API + "tutorial/"
	TUTORIAL_INDICATORS = TUTORIAL + "indicators"

	TRACK        = API + "track"
	SSO          = API + "sso"
	REPORT       = API + "report"
	INTEGRATIONS = API + "integrations"

	USER             = func(uID string) string { return USERS + uID }
	USER_AVATAR      = func(uID, aID string) string { return USERS + uID + "/avatars/" + aID + ".jpg" }
	USER_SETTINGS    = func(uID string) string { return USERS + uID + "/settings" }
	USER_GUILDS      = func(uID string) string { return USERS + uID + "/guilds" }
	USER_CHANNELS    = func(uID string) string { return USERS + uID + "/channels" }
	USER_DEVICES     = func(uID string) string { return USERS + uID + "/devices" }
	USER_CONNECTIONS = func(uID string) string { return USERS + uID + "/connections" }

	GUILD              = func(gID string) string { return GUILDS + gID }
	GUILD_INIVTES      = func(gID string) string { return GUILDS + gID + "/invites" }
	GUILD_CHANNELS     = func(gID string) string { return GUILDS + gID + "/channels" }
	GUILD_MEMBER_DEL   = func(gID, uID string) string { return GUILDS + gID + "/members/" + uID }
	GUILD_BANS         = func(gID string) string { return GUILDS + gID + "/bans" }
	GUILD_BAN          = func(gID, uID string) string { return GUILDS + gID + "/bans/" + uID }
	GUILD_INTEGRATIONS = func(gID string) string { return GUILDS + gID + "/integrations" }
	GUILD_ROLES        = func(gID string) string { return GUILDS + gID + "/roles" }
	GUILD_ROLE         = func(gID, rID string) string { return GUILDS + gID + "/roles/" + rID }
	GUILD_INVITES      = func(gID string) string { return GUILDS + gID + "/invites" }
	GUILD_EMBED        = func(gID string) string { return GUILDS + gID + "/embed" }
	GUILD_PRUNE        = func(gID string) string { return GUILDS + gID + "/prune" }
	GUILD_ICON         = func(gID, hash string) string { return GUILDS + gID + "/icons/" + hash + ".jpg" }

	CHANNEL             = func(cID string) string { return CHANNELS + cID }
	CHANNEL_PERMISSIONS = func(cID string) string { return CHANNELS + cID + "/permissions" }
	CHANNEL_PERMISSION  = func(cID, tID string) string { return CHANNELS + cID + "/permissions/" + tID }
	CHANNEL_INVITES     = func(cID string) string { return CHANNELS + cID + "/invites" }
	CHANNEL_TYPING      = func(cID string) string { return CHANNELS + cID + "/typing" }
	CHANNEL_MESSAGES    = func(cID string) string { return CHANNELS + cID + "/messages" }
	CHANNEL_MESSAGE     = func(cID, mID string) string { return CHANNELS + cID + "/messages/" + mID }
	CHANNEL_MESSAGE_ACK = func(cID, mID string) string { return CHANNELS + cID + "/messages/" + mID + "/ack" }

	INVITE = func(iID string) string { return API + "invite/" + iID }

	INTEGRATIONS_JOIN = func(iID string) string { return API + "integrations/" + iID + "/join" }
)

Functions

This section is empty.

Types

type Attachment

type Attachment struct {
}

An Attachment stores data for message attachments.

type Channel

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

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

type Embed

type Embed struct {
}

An Embed stores data for message embeds.

type Event

type Event struct {
	Type      string          `json:"t"`
	State     int             `json:"s"`
	Operation int             `json:"o"`
	Direction int             `json:"dir"`
	RawData   json.RawMessage `json:"d"`
}

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

type Game added in v0.7.0

type Game struct {
	Name string `json:"name"`
}

type Guild

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

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

type GuildIntegrationsUpdate

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

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

type GuildRole

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

A GuildRole stores data for guild role websocket events.

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 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 {
	MaxAge    int     `json:"max_age"`
	Code      string  `json:"code"`
	Guild     Guild   `json:"guild"`
	Revoked   bool    `json:"revoked"`
	CreatedAt string  `json:"created_at"` // TODO make timestamp
	Temporary bool    `json:"temporary"`
	Uses      int     `json:"uses"`
	MaxUses   int     `json:"max_uses"`
	Inviter   User    `json:"inviter"`
	XkcdPass  bool    `json:"xkcdpass"`
	Channel   Channel `json:"channel"`
}

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"`
	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"`
	Author          User         `json:"author"`
	Content         string       `json:"content"`
	Attachments     []Attachment `json:"attachments"`
	Tts             bool         `json:"tts"`
	Embeds          []Embed      `json:"embeds"`
	Timestamp       string       `json:"timestamp"`
	MentionEveryone bool         `json:"mention_everyone"`
	EditedTimestamp string       `json:"edited_timestamp"`
	Mentions        []User       `json:"mentions"`
	ChannelID       string       `json:"channel_id"`
}

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

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 MessageDelete

type MessageDelete struct {
	ID        string `json:"id"`
	ChannelID string `json:"channel_id"`

} // so much like MessageAck..

A MessageDelete stores data for the message delete websocket event.

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 {
	User    User     `json:"user"`
	Status  string   `json:"status"`
	Roles   []string `json:"roles"`
	GuildID string   `json:"guild_id"`
	Game    Game     `json:"game"`
}

A PresenceUpdate stores data for the pressence update websocket event.

type PrivateChannel

type PrivateChannel struct {
	ID            string `json:"id"`
	IsPrivate     bool   `json:"is_private"`
	LastMessageID string `json:"last_message_id"`
	Recipient     User   `json:"recipient"`

} // merge with channel?

A PrivateChannel stores all data for a specific user private channel.

type ReadState

type ReadState struct {
	MentionCount  int
	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
	PrivateChannels   []PrivateChannel
	Guilds            []Guild
}

A Ready stores all data for the websocket READY event.

type Role

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

A Role stores information about Discord guild member roles.

type Session

type Session struct {
	// General configurable settings.
	Token       string // Authentication token for this session
	Debug       bool   // Debug for printing JSON request/responses
	AutoMention bool   // if set to True, ChannelSendMessage will auto mention <@ID>

	// Settable Callback functions for Websocket Events
	OnEvent                   func(*Session, Event) // should Event be *Event?
	OnReady                   func(*Session, Ready)
	OnTypingStart             func(*Session, TypingStart)
	OnMessageCreate           func(*Session, Message)
	OnMessageUpdate           func(*Session, Message)
	OnMessageDelete           func(*Session, MessageDelete)
	OnMessageAck              func(*Session, MessageAck)
	OnUserUpdate              func(*Session, User)
	OnPresenceUpdate          func(*Session, PresenceUpdate)
	OnVoiceStateUpdate        func(*Session, VoiceState)
	OnChannelCreate           func(*Session, Channel)
	OnChannelUpdate           func(*Session, Channel)
	OnChannelDelete           func(*Session, Channel)
	OnGuildCreate             func(*Session, Guild)
	OnGuildUpdate             func(*Session, Guild)
	OnGuildDelete             func(*Session, Guild)
	OnGuildMemberAdd          func(*Session, Member)
	OnGuildMemberRemove       func(*Session, Member)
	OnGuildMemberDelete       func(*Session, Member) // which is it?
	OnGuildMemberUpdate       func(*Session, Member)
	OnGuildRoleCreate         func(*Session, GuildRole)
	OnGuildRoleUpdate         func(*Session, GuildRole)
	OnGuildRoleDelete         func(*Session, GuildRoleDelete)
	OnGuildIntegrationsUpdate func(*Session, GuildIntegrationsUpdate)
	OnUserSettingsUpdate      func(*Session, map[string]interface{}) // TODO: Find better way?

	// Exposed but should not be modified by User.
	SessionID  string // from websocket READY packet
	DataReady  bool   // Set to true when Data Websocket is ready
	VoiceReady bool   // Set to true when Voice Websocket is ready
	UDPReady   bool   // Set to true when UDP Connection is ready

	// Everything below here is used for Voice testing.
	// This stuff is almost guarenteed to change a lot
	// and is even a bit hackish right now.
	VwsConn    *websocket.Conn // new for voice
	VSessionID string
	VToken     string
	VEndpoint  string
	VGuildID   string
	VChannelID string
	Vop2       VoiceOP2
	UDPConn    *net.UDPConn
	// contains filtered or unexported fields
}

A Session represents a connection to the Discord REST API. token : The authentication token returned from Discord Debug : If set to ture debug logging will be displayed.

func New

func New(args ...interface{}) (s *Session, err error)
type Config struct {
	Debug bool
}

// possible future main struct for discord connection

type Discord struct {
	Debug    bool      // Set to true to enable debug logging
	Token    string    // authentication token
	User     User      // authenticated user info
	Guilds   []Guild   // Cached Guild info
	Channels []Channel // Cached Channel info
	API      api       // all api endpoint functions
	DataWS   dataWS    // data websocket connection
	VoiceWS  voiceWS   // voice websocket/udp connections
	VoiceUDP voiceUDP
}
type api struct {
	Session
}

type dataWS struct { }

type voiceWS struct { }

type voiceUDP struct { }

NOTICE: This function should be considered unstable because I am still exploring the best way to implement my goals here. So, it is more likely to change than than the low level API functions.

New creates a new Discord session interface 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. If you pass a token or username and password (in that order), then it will attempt to login to Discord and open a websocket connection.

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 returend.

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) 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) 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) 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. NOTE, mention and tts parameters may be added in 2.x branch.

func (*Session) ChannelMessages

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

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

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

func (s *Session) Close()

Close closes the connection to the websocket.

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) 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 or leaves a Guild. guildID : The ID of a Guild

func (*Session) GuildEdit

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

GuildEdit edits a new Guild guildID : The ID of a Guild name : A name for the Guild (2-100 characters)

func (*Session) GuildInviteCreate

func (s *Session) GuildInviteCreate(guildID string, i Invite) (st Invite, err error)

GuildInviteCreate creates a new invite for the given guild. guildID : The ID of a Guild. i : An Invite struct with the values MaxAge, MaxUses, Temporary,

and XkcdPass defined.

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) 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) GuildRoleCreate added in v0.7.0

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

GuildRoleCreate returns a new Guild Role

func (*Session) GuildRoleDelete added in v0.7.0

func (s *Session) GuildRoleDelete(guildID, roleID string) (err error)

GuildRoleDelete deletes an existing 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

func (*Session) GuildRoleReorder added in v0.7.0

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

GuildRoleReorder reoders guild 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.

func (*Session) Handshake

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

Handshake sends the client data to Discord during websocket initial connection.

func (*Session) Heartbeat

func (s *Session) Heartbeat(i time.Duration)

Heartbeat sends regular heartbeats to Discord so it knows the client is still connected. If you do not send these heartbeats Discord will disconnect the websocket connection after a few seconds.

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

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

Listen starts listening to the websocket connection for events.

func (*Session) Login

func (s *Session) Login(email string, password string) (token 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) Request

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

Request makes a (GET/POST/...) Requests to Discord REST API. 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 authenticated user's status. If idle>0 then set status to idle. If game>0 then set game. 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) (st User, err error)

UserAvatar returns a ?? 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(userID, recipientID string) (st Channel, err error)

UserChannelCreate creates a new User (Private) Channel with another User userID : A user ID or "@me" which is a shortcut of current user ID recipientID : A user ID for the user to which this channel is opened with.

func (*Session) UserChannels

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

UserChannels returns an array of Channel structures for all private channels for a user userID : A user ID or "@me" which is a shortcut of current user ID

func (*Session) UserGuilds

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

UserGuilds returns an array of Guild structures for all guilds for a given user userID : A user ID or "@me" which is a shortcut of current user ID

func (*Session) UserSettings

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

UserSettings returns the settings for a given user userID : A user ID or "@me" which is a shortcut of current user ID This seems to only return a result for "@me"

func (*Session) UserUpdate added in v0.6.0

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

UserUpdate updates a users settings. userID : A user ID or "@me" which is a shortcut of current user ID

func (*Session) VoiceChannelJoin

func (s *Session) VoiceChannelJoin(guildID, channelID string) (err error)

VoiceChannelJoin joins the authenticated session user to a voice channel. All the voice magic starts with this.

func (*Session) VoiceCloseUDP

func (s *Session) VoiceCloseUDP()

VoiceCloseUDP closes the voice UDP connection.

func (*Session) VoiceCloseWS

func (s *Session) VoiceCloseWS()

Close closes the connection to the voice websocket.

func (*Session) VoiceEvent

func (s *Session) VoiceEvent(messageType int, message []byte) (err error)

VoiceEvent handles any messages received on the voice websocket

func (*Session) VoiceHeartbeat

func (s *Session) VoiceHeartbeat(i time.Duration)

VoiceHeartbeat sends regular heartbeats to voice Discord so it knows the client is still connected. If you do not send these heartbeats Discord will disconnect the websocket connection after a few seconds.

func (*Session) VoiceICE

func (s *Session) VoiceICE() (st VoiceICE, err error)

VoiceICE returns the voice server ICE information

func (*Session) VoiceListen

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

VoiceListen listens on the voice websocket for messages and passes them to the voice event handler.

func (*Session) VoiceListenUDP

func (s *Session) VoiceListenUDP()

VoiceListenUDP is test code to listen for UDP packets

func (*Session) VoiceOpenUDP

func (s *Session) VoiceOpenUDP()

VoiceOpenUDP opens a UDP connect to the voice server and completes the initial required handshake. This connect is left open in the session and can be used to send or receive audio.

func (*Session) VoiceOpenWS

func (s *Session) VoiceOpenWS()

VoiceOpenWS opens a voice websocket connection. This should be called after VoiceChannelJoin is used and the data VOICE websocket events are captured.

func (*Session) VoiceRegions

func (s *Session) VoiceRegions() (st []VoiceRegion, err error)

VoiceRegions returns the voice server regions

func (*Session) VoiceSpeaking

func (s *Session) VoiceSpeaking()

func (*Session) VoiceUDPKeepalive

func (s *Session) VoiceUDPKeepalive(i time.Duration)

VoiceUDPKeepalive sends a packet to keep the UDP connection forwarding alive for NATed clients. Without this no audio can be received after short periods of silence. Not sure how often this is supposed to be sent or even what payload I am suppose to be sending. So this is very.. unfinished :)

type Settings

type Settings struct {
	RenderEmbeds          bool     `json:"render_embeds"`
	InlineEmbedMedia      bool     `json:"inline_embed_media"`
	EnableTtsCommand      bool     `json:"enable_tts_command"`
	MessageDisplayCompact bool     `json:"message_display_compact"`
	Locale                string   `json:"locale"`
	ShowCurrentGame       bool     `json:"show_current_game"`
	Theme                 string   `json:"theme"`
	MutedChannels         []string `json:"muted_channels"`
}

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

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"`
	Verified bool   `json:"verified"`
}

A User stores all data for an individual Discord user.

type VEvent

type VEvent struct {
	Type      string          `json:"t"`
	State     int             `json:"s"`
	Operation int             `json:"op"`
	RawData   json.RawMessage `json:"d"`
}

A VEvent is the initial structure for voice websocket events. I think I can reuse the data websocket structure here.

type VoiceICE

type VoiceICE struct {
	TTL     string      `json:"ttl"`
	Servers []ICEServer `json:"servers"`
}

A VoiceICE stores data for voice ICE servers.

type VoiceOP2

type VoiceOP2 struct {
	SSRC              uint32        `json:"ssrc"`
	Port              int           `json:"port"`
	Modes             []string      `json:"modes"`
	HeartbeatInterval time.Duration `json:"heartbeat_interval"`
}

A VoiceOP2 stores the data for voice operation 2 websocket events which is sort of like the voice READY packet

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 VoiceState

type VoiceState struct {
	UserID    string `json:"user_id"`
	Suppress  bool   `json:"suppress"`
	SessionID string `json:"session_id"`
	SelfMute  bool   `json:"self_mute"`
	SelfDeaf  bool   `json:"self_deaf"`
	Mute      bool   `json:"mute"`
	Deaf      bool   `json:"deaf"`
	ChannelID string `json:"channel_id"`
}

A VoiceState stores the voice states of Guilds

Directories

Path Synopsis
example
api_basic
This file provides a basic "quick start" example of using the Discordgo package to connect to Discord using the low level API functions.
This file provides a basic "quick start" example of using the Discordgo package to connect to Discord using the low level API functions.
new_basic
This file provides a basic "quick start" example of using the Discordgo package to connect to Discord using the New() helper function.
This file provides a basic "quick start" example of using the Discordgo package to connect to Discord using the New() helper function.

Jump to

Keyboard shortcuts

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