当前位置: 首页>>代码示例>>Golang>>正文


Golang Session.Open方法代码示例

本文整理汇总了Golang中github.com/bwmarrin/discordgo.Session.Open方法的典型用法代码示例。如果您正苦于以下问题:Golang Session.Open方法的具体用法?Golang Session.Open怎么用?Golang Session.Open使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在github.com/bwmarrin/discordgo.Session的用法示例。


在下文中一共展示了Session.Open方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的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
}
开发者ID:Xackery,项目名称:discordeq,代码行数:30,代码来源:discord.go

示例2: doWsHandshake

func doWsHandshake(dg *discordgo.Session) error {
	var err error

	// open websocket...
	err = dg.Open()
	if err != nil {
		log.Errorf("Problem opening WS: %s", err)
		return err
	}

	err = dg.Handshake()
	if err != nil {
		log.Errorf("Problem handshaking WS: %s", err)
	}
	return err
}
开发者ID:Skullever,项目名称:digo,代码行数:16,代码来源:conn.go

示例3: 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
}
开发者ID:Skullever,项目名称:digo,代码行数:44,代码来源:api_basic.go

示例4: main

func main() {
	logInfo("Logging in...")
	var err error
	var session *discordgo.Session
	if accountToken == "" {
		logInfo("Logging in with username and password...")
		session, err = discordgo.New(username, password)
	} else {
		logInfo("Logging in with bot account token...")
		session, err = discordgo.New(accountToken)
	}
	setupHandlers(session)
	panicOnErr(err)
	logInfo("Opening session...")
	err = session.Open()
	panicOnErr(err)
	logInfo("Sleeping...")
	<-make(chan struct{})
}
开发者ID:dhedegaard,项目名称:notibot,代码行数:19,代码来源:notibot.go


注:本文中的github.com/bwmarrin/discordgo.Session.Open方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。