本文整理匯總了Golang中github.com/bwmarrin/discordgo.Session.StateEnabled方法的典型用法代碼示例。如果您正苦於以下問題:Golang Session.StateEnabled方法的具體用法?Golang Session.StateEnabled怎麽用?Golang Session.StateEnabled使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類github.com/bwmarrin/discordgo.Session
的用法示例。
在下文中一共展示了Session.StateEnabled方法的1個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Golang代碼示例。
示例1: ListenToDiscord
func ListenToDiscord(config *eqemuconfig.Config, disco *discord.Discord) (err error) {
var session *discordgo.Session
var guild *discordgo.Guild
//log.Println("Listen to discord..")
if session, err = disco.GetSession(); err != nil {
log.Printf("[Discord] Failed to get instance %s: %s (Make sure bot is part of server)", config.Discord.ServerID, err.Error())
return
}
if guild, err = session.Guild(config.Discord.ServerID); err != nil {
log.Printf("[Discord] Failed to get server %s: %s (Make sure bot is part of server)", config.Discord.ServerID, err.Error())
return
}
isNotAvail := true
if guild.Unavailable == &isNotAvail {
log.Printf("[Discord] Failed to get server %s: Server unavailable (Make sure bot is part of server, and has permission)", config.Discord.ServerID, err.Error())
return
}
session.StateEnabled = true
session.AddHandler(messageCreate)
log.Printf("[Discord] Connected\n")
if err = session.Open(); err != nil {
log.Printf("[Discord] Session closed: %s", err.Error())
return
}
select {}
return
}