本文整理匯總了Golang中github.com/bwmarrin/discordgo.Session.Listen方法的典型用法代碼示例。如果您正苦於以下問題:Golang Session.Listen方法的具體用法?Golang Session.Listen怎麽用?Golang Session.Listen使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類github.com/bwmarrin/discordgo.Session
的用法示例。
在下文中一共展示了Session.Listen方法的2個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Golang代碼示例。
示例1: dgoListen
func dgoListen(s *discordgo.Session) error {
log.Notice("Digo listening for WS Events")
// Listen blocks until it returns
//go acceptInvite(s)
err := s.Listen()
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
}