|
9 vuotta sitten | |
---|---|---|
.travis.yml | 9 vuotta sitten | |
LICENSE | 9 vuotta sitten | |
README.md | 9 vuotta sitten | |
discord.go | 9 vuotta sitten | |
endpoints.go | 9 vuotta sitten | |
restapi.go | 9 vuotta sitten | |
structs.go | 9 vuotta sitten | |
util.go | 9 vuotta sitten | |
voice.go | 9 vuotta sitten | |
wsapi.go | 9 vuotta sitten |
This package provides low level bindings for the Discord REST & Websocket API in the Go Programming Language (Golang).
See out dgVoice for experimental Discord voice support.
See out dgTest for more examples and test code.
package main
import (
"fmt"
"os"
"time"
"github.com/bwmarrin/discordgo"
)
func main() {
var err error
var username, password, token string
// Check for Username and Password arguments
if len(os.Args) < 2 || len(os.Args) > 3 {
fmt.Println("You must provide a username and password as arguments. See below example.")
fmt.Println(os.Args[0], " [username] [password]")
return
}
// Set username and password from command line arguments.
username = os.Args[1]
password = os.Args[2]
// 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, unless the token was already provided.
if token == "" {
Session.Token, err = Session.Login(username, password)
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("%20s %20s %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.
Go: gdraynz/go-discord, Xackery/discord, Nerketur/discordapi
.NET: RogueException/Discord.Net, Luigifan/DiscordSharp
Java: nerd/Discord4J
Node.js: izy521/discord.io, hydrabolt/discord.js, qeled/discordie,
PHP: Cleanse/discord-hypertext, teamreflex/DiscordPHP
Python: Rapptz/discord.py
Ruby: meew0/discordrb
Scala: eaceaser/discord-akka
Rust: SpaceManiac/discord-rs