(Golang) Go bindings for Discord
Find a file
2015-11-25 19:28:53 -06:00
.travis.yml First commit of Travis CI file 2015-11-16 15:09:09 -06:00
discord.go Reworded package comment 2015-11-23 10:17:10 -06:00
endpoints.go Reworded top comment 2015-11-23 10:16:23 -06:00
LICENSE Initial commit 2015-11-01 14:51:01 -06:00
README.md Link to dgVoice added 2015-11-23 09:48:41 -06:00
restapi.go All REST API JSON now created via structs instead of interface or strings 2015-11-24 16:17:14 -06:00
structs.go Added VoiceReady, DataReady, and UDPReady flags to Session struct 2015-11-25 19:28:53 -06:00
util.go Reworded top comment 2015-11-23 10:16:23 -06:00
voice.go Check that websocket exists before trying to send VoiceSpeaking 2015-11-25 08:31:26 -06:00
wsapi.go Few notes, also, send 1st data websocket heartbeat immediately. 2015-11-25 08:47:15 -06:00

Discordgo

This package provides low level bindings for the Discord REST & Websocket API in the Go Programming Language (Golang).

Check out dgVoice for experimental Discord voice support.

GoDoc Go Walker Go report Build Status

Usage Example

package main

import (
	"fmt"
	"time"

	"github.com/bwmarrin/discordgo"
)

func main() {

	var err error

	// Create a new Discord Session and set a handler for the OnMessageCreate
    // event that happens for every new message on any channel
	Session := discordgo.Session{
		OnMessageCreate: messageCreate,
	}

	// Login to the Discord server and store the authentication token
	// inside the Session
	Session.Token, err = Session.Login("coolusername", "cleverpassword")
	if err != nil {
		fmt.Println(err)
		return
	}

	// Open websocket connection
	err = Session.Open()
	if err != nil {
		fmt.Println(err)
	}

	// Do websocket handshake.
	err = Session.Handshake()
	if err != nil {
		fmt.Println(err)
	}

	// Listen for events.
	Session.Listen()
	return
}

func messageCreate(s *discordgo.Session, m discordgo.Message) {
	fmt.Printf("%25d %s %20s > %s\n", m.ChannelID, time.Now().Format(time.Stamp), m.Author.Username, m.Content)
}

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
  • Hand crafted documentation coming soon.

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
  • Voice Channel support.
  • Add a higher level interface with user friendly helper functions.

Credits

Special thanks goes to both the below projects who helped me get started with this project. If you're looking for alternative Golang interfaces to Discord please check both of these out.

Other Discord APIs