@@ -70,8 +70,12 @@ type Gateway struct {
7070}
7171
7272func New (state State ) * Gateway {
73+ // https://discordapp.com/developers/docs/topics/voice-connections#establishing-a-voice-websocket-connection
74+ var endpoint = "wss://" + strings .TrimSuffix (state .Endpoint , ":80" ) + "/?v=" + Version
75+
7376 return & Gateway {
7477 state : state ,
78+ WS : wsutil .New (endpoint ),
7579 Timeout : wsutil .WSTimeout ,
7680 ErrorLog : wsutil .WSError ,
7781 AfterClose : func (error ) {},
@@ -96,7 +100,6 @@ func (c *Gateway) OpenCtx(ctx context.Context) error {
96100 var endpoint = "wss://" + strings .TrimSuffix (c .state .Endpoint , ":80" ) + "/?v=" + Version
97101
98102 wsutil .WSDebug ("Connecting to voice endpoint (endpoint=" + endpoint + ")" )
99- c .WS = wsutil .New (endpoint )
100103
101104 // Create a new context with a timeout for the connection.
102105 ctx , cancel := context .WithTimeout (ctx , c .Timeout )
@@ -308,14 +311,6 @@ func (c *Gateway) Send(code OPCode, v interface{}) error {
308311}
309312
310313func (c * Gateway ) SendCtx (ctx context.Context , code OPCode , v interface {}) error {
311- if c .WS == nil {
312- return errors .New ("tried to send data to a connection without a Websocket" )
313- }
314-
315- if c .WS .Conn == nil {
316- return errors .New ("tried to send data to a connection with a closed Websocket" )
317- }
318-
319314 var op = wsutil.OP {
320315 Code : code ,
321316 }
0 commit comments