discord

package module
v0.0.0-...-1722250 Latest Latest
Warning

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

Go to latest
Published: Jan 12, 2016 License: GPL-2.0 Imports: 10 Imported by: 0

README

discord - THIS IS NOW DEPRECATED

A Discord API for Golang

godoc badge Go report Build Status Features

  • Log In/Out
  • List Guilds
  • List Channels
  • Send Message to Guild/Channel
  • Connect via Websocket, Trigger functions on Events

Example

	client := discord.Client{}
	err := client.Login(email, password)
	if err != nil {
		log.Println("Error Logging in:", err.Error())
		return
	}

	guilds, err := client.UserGuilds()
	if err != nil {
		log.Println("Error getting guilds:", err.Error())
	}
	log.Println("Guild size:", len(guilds))
	if len(guilds) < 1 {
		log.Println("no guilds, exiting")
		return
	}

	guild := guilds[0]
	channels, err := client.GuildChannels(guild.ID)
	if err != nil {
		log.Println("Error getting channels:", err.Error())
		return
	}
	log.Println("Channel size:", len(channels))
	for _, channel := range channels {
		if channel.Name == "test" {
			log.Println("Sending message to ", channel.ID)
			resp, err := client.ChannelMessageSend(channel.ID, "So this method works...")
			if err != nil {
				log.Println("Error messaging:", err.Error())
				return
			}
			log.Println("Done", resp)
			return
		}
	}

Documentation

Index

Constants

View Source
const DISCORD_URL = "https://discordapp.com/api"

Discord URL path

Variables

This section is empty.

Functions

This section is empty.

Types

type Attachment

type Attachment struct {
	Width    int
	Url      string
	Size     int
	ProxyURL string
	ID       int `json:"id,string"`
	Filename string
}

Attachment array entry

type Author

type Author struct {
	Username      string
	Discriminator int `json:",string"`
	ID            int `json:"id,string"`
	Avatar        string
}

An author of a message

type Channel

type Channel struct {
	GuildID              int `json:"guild_id,string,omitempty"`
	Name                 string
	PermissionOverwrites []PermissionOverwrites `json:"permission_overwrites,omitempty"`
	Topic                string
	Position             int    `json:",omitempty"`
	LastMessageID        string `json:"last_message_id"`
	Type                 string
	ID                   int `json:",string,omitempty"`
	IsPrivate            bool
}

Channels are sections inside guilds that messages are grouped by

type Client

type Client struct {
	User
	Token      string
	GatewayURL string `json:"url"`

	Guilds                    []Guild
	PrivateChannel            []PrivateChannel
	OnReady                   func(Event, Ready)
	OnTypingStart             func(Event, TypingEvent)
	OnMessageCreate           func(Event, Message)
	OnMessageUpdate           func(Event, Message)
	OnMessageDelete           func(Event, Message)
	OnPresenceStart           func(Event, Presence)
	OnPresenceUpdate          func(Event, Presence)
	OnUserSettingsUpdate      func(Event, UserSettings)
	OnGuildCreate             func(Event, GuildCreateEvent)
	OnGuildUpdate             func(Event, Guild)
	OnGuildDelete             func(Event, GuildDeleteEvent)
	OnGuildIntegrationsUpdate func(Event, GuildMemberEvent)
	OnGuildMemberAdd          func(Event, GuildMemberEvent)
	OnGuildMemberUpdate       func(Event, GuildMemberEvent)
	OnGuildMemberRemove       func(Event, GuildMemberEvent)
	OnGuildRoleDelete         func(Event, GuildRoleDeleteEvent)
	OnGuildRoleUpdate         func(Event, Guild)
	OnGuildRoleCreate         func(Event, GuildRoleEvent)
	OnVoiceStateUpdate        func(Event, VoiceState)
	// contains filtered or unexported fields
}

Client wraps all Discord methods

func (*Client) ChannelMessageSend

func (c *Client) ChannelMessageSend(channelId int, messageText string) (responseMessage Message, err error)

Send a message to specified channel

func (*Client) GuildChannels

func (c *Client) GuildChannels(guildId int) (channels []Channel, err error)

List channels found on given guildId

func (*Client) IsLoggedIn

func (c *Client) IsLoggedIn() (isLoggedIn bool)

IsLoggedIn returns if client is logged in to discord

func (*Client) Listen

func (c *Client) Listen() (err error)

Listen to websocket connection

func (*Client) Login

func (c *Client) Login(email string, pass string) (err error)

Login Method for Discord

func (*Client) StopListen

func (c *Client) StopListen()

Stop listening for websocket data

func (Client) UserGuilds

func (c Client) UserGuilds() (guilds []Guild, err error)

Get a list of guilds for current logged in user

func (*Client) UserMe

func (c *Client) UserMe() (err error)

Fetch information about user logged in (me)

type Embed

type Embed struct {
	Author      Author
	Description string
	Provider    Provider
	Thumbnail   Thumbnail
	Title       string
	Type        string
	Url         string
	Video       Video
}

Embedded media array entry

type Event

type Event struct {
	Type      string          `json:"t"`
	State     int             `json:"s"`
	Operation int             `json:"o"`
	Direction int             `json:"dir"` //Direction of command, 0-received, 1-sent
	RawData   json.RawMessage `json:"d"`
}

type Guild

type Guild struct {
	VoiceStates    []VoiceState //Used by Websocket
	JoinedAt       string
	AfkChannelID   int `json:"afk_channel_id,string,omitempty"`
	AfkTimeout     int
	ID             int `json:"id,string,omitempty"`
	Icon           int `json:"omitempty"`
	Name           string
	Roles          []Role
	Region         string
	Presences      []Presence //Used by Websocket
	EmbedChannelID int        `json:"embed_channel_id,string,omitempty"`
	EmbedEnabled   bool
	OwnerID        int `json:"owner_id,string,omitempty"`
	Members        []Member
	Large          bool      //Used by Websocket
	Channels       []Channel //Used by Websocket
}

A guild are basically servers on Discord

type GuildCreateEvent

type GuildCreateEvent struct {
	ID string `json:"id,string"`
	// contains filtered or unexported fields
}

type GuildDeleteEvent

type GuildDeleteEvent struct {
	GuildCreateEvent
}

type GuildMemberEvent

type GuildMemberEvent struct {
	JoinedAt string
	GuildID  int `json:"guild_id,string"`
	Roles    []Role
	User     User
}

type GuildRoleDeleteEvent

type GuildRoleDeleteEvent struct {
	GuildID int `json:"guild_id,string"`
	RoleID  int `json:"role_id, string"`
}

GuildRoleDelete is used when a delete roleevent occurs for guild

type GuildRoleEvent

type GuildRoleEvent struct {
	GuildID int `json:"guild_id,string"`
	Role    Role
}

GuildRole is used when a CRUD operation happens with roles in a guild

type Member

type Member struct {
	User     User
	Roles    []string
	Mute     bool
	JoinedAt string
	Deaf     bool
}

type Message

type Message struct {
	Attachments     []Attachment
	Tts             bool
	Embeds          []Embed
	Timestamp       string
	MentionEveryone bool
	Nonce           string //Used by websocket
	ID              int    `json:"id,string,omitempty"`
	EditedTimestamp string
	Author          User
	Content         string
	ChannelID       int `json:"channel_id,string,omitempty"`
	Mentions        []User
}

Posted message inside a channel

type PermissionOverwrites

type PermissionOverwrites struct {
}

Channel setting regarding if a permission overwrites

type Presence

type Presence struct {
	User    User
	Status  string
	Roles   []string
	GuildID int `json:"guild_id,string"`
	GameID  int `json:"game_id"`
}

type PrivateChannel

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

Private Channels between two users

type Provider

type Provider struct {
	Name string
	Url  string
}

type ReadState

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

type Ready

type Ready struct {
	Version           int `json:"v"`
	User              User
	SessionID         string
	ReadState         []ReadState
	PrivateChannels   []PrivateChannel
	HeartbeatInterval time.Duration `json:"heartbeat_interval"`
	Guilds            []Guild
}

type Role

type Role struct {
	Managed     bool
	Name        string
	Color       int
	Hoist       bool
	Position    int
	ID          int `json:"id,string"`
	Permissions int
}

Roles are permission groupings

type Thumbnail

type Thumbnail struct {
	Height   int
	ProxyUrl string
	Url      string
	Width    int
}

type TypingEvent

type TypingEvent struct {
	UserID    int `json:"user_id,string"`
	Timestamp int
	ChannelID int `json:"channel_id,string"`
}

type User

type User struct {
	ID            int `json:"id,string"`
	Username      string
	Email         string
	Verified      bool
	Avatar        string
	Discriminator int `json:"string"`
}

type UserSettings

type UserSettings struct {
	InlineAttachmentMedia bool
	InlineEmbedMedia      bool
	MutedChannels         []string
	RenderEmbeds          bool
	Theme                 string
}

type Video

type Video struct {
	Height int
	Url    string
	Width  int
}

type VoiceState

type VoiceState struct {
	UserID    int `json:"string"`
	Suppress  bool
	SessionID string `json:"session_id"`
	SelfMute  bool
	SelfDeaf  bool
	Mute      bool
	Deaf      bool
	ChannelID int `json:"channel_id,string"`
}

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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