# discordapi
A GoLang API wrapper for the Discord REST API (unofficial) and preliminary websockets

v0.8.0 alpha

This is a simple low-level REST API Wrapper for Discord.  I am not affiliated with or endorsed by Discord at all, this is meant as a way to learn Go better as a language.  It may contain errors, bugs, and any other such oddities, but it seems to work for me :)

Later on, I will have better websocket support, but if you want a good one right now, then please use [go-discord]( instead (or in addition to mine)!

Version system will be sporadic until 1.0, safe to ignore, other than alpha means preliminary, beta means set on paper, and stable means more or less set in stone.


Please note that *as-is*, this example will only work if run with *your* account info.  To get it to work with others, follow the comments instructions.
package main

import (

func parseCmd(c discord.Discord, data discord.MESSAGE_CREATE) {
	//check that prefix is there
	cmdPrefix := "/gogogobot "
	if !strings.HasPrefix(data.Content, cmdPrefix) {
	if data.Author.ID != c.Me.ID {  //comment out before uncommenting below
	//if data.Author.Name != "Name" { //use this instead for checking names
	//if data.Author.ID != "UserID" { //use this instead to check for a User ID (string of numbers)
		//c.SendTextMsg("Sorry, you can't use this command", data.ChanID)
	doCmd := strings.Trim(strings.TrimPrefix(data.Content, cmdPrefix), " \n\r\t")
	switch doCmd {
	case "quit":
		c.SendTextMsg("Stopping bot!", data.ChanID)
	case "hello":
		c.SendTextMsg("Hello World!", data.ChanID)
	case "version":
		c.SendTextMsg("Running version: " + discord.Version(), data.ChanID)
		c.SendTextMsg(fmt.Sprintf("I don't know how to %s.", doCmd), data.ChanID)

func callback(cl discord.Discord, event string, data interface{}) {
	fmt.Println("\tuser callback called:", event)
	if mc, ok := data.(discord.MESSAGE_CREATE); ok {
		parseCmd(cl, mc)

func main() {
	client, err := discord.Login("", "12345")
	if err != nil {
	if client.Client == nil {
		fmt.Println("Empty client!  Check your network connection.")
	fmt.Println("Attempting websocket connection...")
	call := discord.Callback(callback)
	err = client.WSConnect(&call) // required if websockets is desired
	if err != nil {
		fmt.Println("websocket error:", err)
	} else {
		fmt.Println("websocket connected!")
	defer func() {
		err = client.Logout()
		if err != nil {
	//other code

This is in ALPHA stage which means nothing is guaranteed to stay the same.  Things will likely change, and there will be absolutely NO attempt to maintain backwards compatibility until version 1.0.  This means things can and likely will break if this is used, upon upgrading to new versions.  Do not use for time- or safety-critical tasks.  You have been warned.

##Other libraries
- []( (Python)
- [discord.js]( (JS)
- []( (JS)
- [Discord.NET]( (C#)
- [DiscordSharp]( (C#)
- [Discord4J]( (Java)
- [discordrb]( (Ruby)
- [Discordgo]( (Go)
- [discord]( (Go)
- [go-discord]( (Go)

Imports 1 package(s) ΒΆ