From f05856893b7f6de3960900ad0bf2d188ac4b8216 Mon Sep 17 00:00:00 2001 From: Bruce Date: Tue, 11 Apr 2017 15:06:46 +0000 Subject: [PATCH] Updated MyToken example code and readme. --- examples/mytoken/README.md | 28 +++++++++++++++++----------- examples/mytoken/main.go | 7 +++++++ 2 files changed, 24 insertions(+), 11 deletions(-) diff --git a/examples/mytoken/README.md b/examples/mytoken/README.md index fa77bab..6db8bfb 100644 --- a/examples/mytoken/README.md +++ b/examples/mytoken/README.md @@ -1,15 +1,27 @@ -MyToken Example -==== -This example demonstrates how to utilize DiscordGo to print out the -Authentication Token for a given user account. +## DiscordGo MyToken Example + +This example demonstrates how to utilize DiscordGo to login with an email and +password then to print out the Authentication Token for that user's account. + +Everytime this application is run a new authentication token is generated +for your account. Logging you in via email and password then creating a new +token is a cpu/mem expensive task for Discord. Because of that, it is highly +recommended to avoid doing this very often. Please only use this once to get a +token for your use and then always just your token. + +**Join [Discord Gophers](https://discord.gg/0f1SbxBZjYoCtNPP) +Discord chat channel for support.** ### Build This assumes you already have a working Go environment setup and that DiscordGo is correctly installed on your system. +From within the mytoken example folder, run the below command to compile the +example. + ```sh go build ``` @@ -31,11 +43,5 @@ The below example shows how to start the program using an Email and Password for authentication. ```sh -./mytoken -e EmailHere -p PasswordHere -``` - -The below example shows how to start the bot using the bot user's token - -```sh -./mytoken -t "Bot YOUR_BOT_TOKEN" +./mytoken -e youremail@here.com -p MySecretPassword ``` diff --git a/examples/mytoken/main.go b/examples/mytoken/main.go index 5914fc8..9375ead 100644 --- a/examples/mytoken/main.go +++ b/examples/mytoken/main.go @@ -3,6 +3,7 @@ package main import ( "flag" "fmt" + "os" "github.com/bwmarrin/discordgo" ) @@ -18,6 +19,11 @@ func init() { flag.StringVar(&Email, "e", "", "Account Email") flag.StringVar(&Password, "p", "", "Account Password") flag.Parse() + + if Email == "" || Password == "" { + flag.Usage() + os.Exit(1) + } } func main() { @@ -29,5 +35,6 @@ func main() { return } + // Print out your token. fmt.Printf("Your Authentication Token is:\n\n%s\n", dg.Token) }