2.5 KiB
2.5 KiB
Discordgo
A Discord API for Golang
Discordgo provides an almost complete low-level Golang interface to the Discord REST and Websocket API layers. The majority of both of these interfaces are complete and I should have the remaining functions finished soon.
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)
}
What Works
Low level functions exist for the majority of the REST and Websocket 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 Left
- Permissions related functions.
- Editing User Profile settings
- Voice Channel support.
- Functions for Maintenance Status
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.