diff --git a/main.go b/main.go index 3043834..991cabf 100644 --- a/main.go +++ b/main.go @@ -48,8 +48,9 @@ func main() { cfg = ini.Empty() } - if !cfg.Section("auth").HasKey("email") || - !cfg.Section("auth").HasKey("password") { + if (!cfg.Section("auth").HasKey("email") || + !cfg.Section("auth").HasKey("password")) && + !cfg.Section("auth").HasKey("token") { cfg.Section("auth").NewKey("email", "your@email.com") cfg.Section("auth").NewKey("password", "yourpassword") cfg.Section("channels").NewKey("channelid1", "C:\\full\\path\\1") @@ -86,9 +87,14 @@ func main() { return } - dg, err := discordgo.New( - cfg.Section("auth").Key("email").String(), - cfg.Section("auth").Key("password").String()) + var dg *discordgo.Session + if cfg.Section("auth").HasKey("token") { + dg, err = discordgo.New(cfg.Section("auth").Key("token").String()) + } else { + dg, err = discordgo.New( + cfg.Section("auth").Key("email").String(), + cfg.Section("auth").Key("password").String()) + } if err != nil { fmt.Println("error creating Discord session,", err) return diff --git a/readme.md b/readme.md index 9e3088b..66fd1a8 100644 --- a/readme.md +++ b/readme.md @@ -5,5 +5,7 @@ This is a simple tool which downloads pictures posted in discord channels of you ## How to use? When you run the tool for the first time it creates an `config.ini` file with example values. Edit these values and run the tool for a second time. It should connect to discords api and wait for new messages. +In case you are using two-factor authentication you have to login using your token. Remove the the email and password lines under the auth section in the config file and instead put in `token = `. You can acquire your token from the developer tools in your browser (`localStorage.token`). + ### Where do I get the channel id? Open discord in your browser and go to the channel you want to monitor. In your adress bar should be an URL like `https://discordapp.com/channels/1234/5678`. The number after the last slash is the channel id, in this case `5678`.