|
%!s(int64=9) %!d(string=hai) anos | |
---|---|---|
.travis.yml | %!s(int64=9) %!d(string=hai) anos | |
LICENSE | %!s(int64=9) %!d(string=hai) anos | |
README.md | %!s(int64=9) %!d(string=hai) anos | |
discord.go | %!s(int64=9) %!d(string=hai) anos | |
endpoints.go | %!s(int64=9) %!d(string=hai) anos | |
restapi.go | %!s(int64=9) %!d(string=hai) anos | |
structs.go | %!s(int64=9) %!d(string=hai) anos | |
util.go | %!s(int64=9) %!d(string=hai) anos | |
voice.go | %!s(int64=9) %!d(string=hai) anos | |
wsapi.go | %!s(int64=9) %!d(string=hai) anos |
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.
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)
}
NOTICE : This library and the Discord API are unfinished. Because of that there may be major changes to library functions, constants, and structures.
Current package provides a low level direct mapping to the majority of Discord REST and Websock API.
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.