本文整理汇总了Golang中github.com/bwmarrin/discordgo.Session.Login方法的典型用法代码示例。如果您正苦于以下问题:Golang Session.Login方法的具体用法?Golang Session.Login怎么用?Golang Session.Login使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类github.com/bwmarrin/discordgo.Session
的用法示例。
在下文中一共展示了Session.Login方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。
示例1: doLogin
func doLogin(s *discordgo.Session) error {
var err error
var token string
c := config.Get()
log.Debug("Logging in")
token, err = s.Login(c.Email, c.Password)
if err == nil {
if token != "" {
s.Token = token
}
} else {
log.Errorf("Can't log in: %s", err)
log.Error("Maybe your credentials are invalid?")
}
// since we're dealing with a ref, only return the error
return err
}
示例2: main
func main() {
var err error
// Check for Username and Password CLI arguments.
if len(os.Args) != 3 {
fmt.Println("You must provide username and password as arguments. See below example.")
fmt.Println(os.Args[0], " [username] [password]")
return
}
// Create a new Discord Session interface and set a handler for the
// OnMessageCreate event that happens for every new message on any channel
dg := discordgo.Session{
OnMessageCreate: messageCreate,
}
// Login to the Discord server and store the authentication token
dg.Token, err = dg.Login(os.Args[1], os.Args[2])
if err != nil {
fmt.Println(err)
return
}
// Open websocket connection
err = dg.Open()
if err != nil {
fmt.Println(err)
}
// Do websocket handshake.
err = dg.Handshake()
if err != nil {
fmt.Println(err)
}
// Listen for events.
go dg.Listen()
// Simple way to keep program running until any key press.
var input string
fmt.Scanln(&input)
return
}