forked from pothtonswer/discordmuffin
Non-New() Methods no longer officially supported.
This commit is contained in:
parent
7bd2bb19d8
commit
d69fac5eae
2 changed files with 0 additions and 107 deletions
|
@ -1,41 +0,0 @@
|
||||||
<img align="right" src="http://bwmarrin.github.io/discordgo/img/discordgo.png">
|
|
||||||
Basic API Example
|
|
||||||
====
|
|
||||||
|
|
||||||
This example demonstrates how to utilize DiscordGo to connect to Discord
|
|
||||||
and print out all received chat messages.
|
|
||||||
|
|
||||||
This example uses the low-level REST API functions to connect to Discord.
|
|
||||||
|
|
||||||
### Build
|
|
||||||
|
|
||||||
This assumes you already have a working Go environment setup and that
|
|
||||||
DiscordGo is correctly installed on your system.
|
|
||||||
|
|
||||||
```sh
|
|
||||||
go build
|
|
||||||
```
|
|
||||||
|
|
||||||
### Usage
|
|
||||||
|
|
||||||
You must authenticate using either an Authentication Token or both Email and
|
|
||||||
Password for an account. Keep in mind official Bot accounts only support
|
|
||||||
authenticating via Token.
|
|
||||||
|
|
||||||
```
|
|
||||||
./api_basic --help
|
|
||||||
Usage of ./api_basic:
|
|
||||||
-e string
|
|
||||||
Account Email
|
|
||||||
-p string
|
|
||||||
Account Password
|
|
||||||
-t string
|
|
||||||
Account Token
|
|
||||||
```
|
|
||||||
|
|
||||||
The below example shows how to start the bot using an Email and Password for
|
|
||||||
authentication.
|
|
||||||
|
|
||||||
```sh
|
|
||||||
./api_basic -e EmailHere -p PasswordHere
|
|
||||||
```
|
|
|
@ -1,66 +0,0 @@
|
||||||
// This file provides a basic "quick start" example of using the Discordgo
|
|
||||||
// package to connect to Discord using the low level API functions.
|
|
||||||
package main
|
|
||||||
|
|
||||||
import (
|
|
||||||
"flag"
|
|
||||||
"fmt"
|
|
||||||
"time"
|
|
||||||
|
|
||||||
"github.com/bwmarrin/discordgo"
|
|
||||||
)
|
|
||||||
|
|
||||||
var (
|
|
||||||
Email string
|
|
||||||
Password string
|
|
||||||
Token string
|
|
||||||
BotID string
|
|
||||||
)
|
|
||||||
|
|
||||||
func init() {
|
|
||||||
|
|
||||||
flag.StringVar(&Email, "e", "", "Account Email")
|
|
||||||
flag.StringVar(&Password, "p", "", "Account Password")
|
|
||||||
flag.StringVar(&Token, "t", "", "Account Token")
|
|
||||||
flag.Parse()
|
|
||||||
}
|
|
||||||
|
|
||||||
func main() {
|
|
||||||
|
|
||||||
// Create a new Discord Session struct and set a handler for the
|
|
||||||
dg := discordgo.Session{}
|
|
||||||
|
|
||||||
// Register messageCreate as a callback for the messageCreate events.
|
|
||||||
dg.AddHandler(messageCreate)
|
|
||||||
|
|
||||||
// If no Authentication Token was provided login using the
|
|
||||||
// provided Email and Password.
|
|
||||||
if Token == "" {
|
|
||||||
err := dg.Login(Email, Password)
|
|
||||||
if err != nil {
|
|
||||||
fmt.Println("error logging into Discord,", err)
|
|
||||||
return
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
dg.Token = Token
|
|
||||||
}
|
|
||||||
|
|
||||||
// Open websocket connection to Discord
|
|
||||||
err := dg.Open()
|
|
||||||
if err != nil {
|
|
||||||
fmt.Println(err)
|
|
||||||
}
|
|
||||||
|
|
||||||
fmt.Println("Bot is now running. Press CTRL-C to exit.")
|
|
||||||
// Simple way to keep program running until CTRL-C is pressed.
|
|
||||||
<-make(chan struct{})
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
// This function will be called (due to AddHandler above) every time a new
|
|
||||||
// message is created on any channel that the autenticated bot has access to.
|
|
||||||
func messageCreate(s *discordgo.Session, m *discordgo.MessageCreate) {
|
|
||||||
|
|
||||||
// Print message to stdout.
|
|
||||||
fmt.Printf("%20s %20s %20s > %s\n", m.ChannelID, time.Now().Format(time.Stamp), m.Author.Username, m.Content)
|
|
||||||
}
|
|
Loading…
Reference in a new issue