Exemplo n.º 1
0
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
}
Exemplo n.º 2
0
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
}