コード例 #1
0
        internal async Task SendIdentifyAsync(StatusUpdate status)
        {
            var identify = new GatewayIdentify
            {
                Token          = Utilities.GetFormattedToken(this),
                Compress       = this.Configuration.GatewayCompressionLevel == GatewayCompressionLevel.Payload,
                LargeThreshold = this.Configuration.LargeThreshold,
                ShardInfo      = new ShardInfo
                {
                    ShardId    = this.Configuration.ShardId,
                    ShardCount = this.Configuration.ShardCount
                },
                Presence = status,
                Intents  = this.Configuration.Intents
            };
            var payload = new GatewayPayload
            {
                OpCode = GatewayOpCode.Identify,
                Data   = identify
            };
            var payloadstr = JsonConvert.SerializeObject(payload);

            await this.WsSendAsync(payloadstr).ConfigureAwait(false);

            if (this.Configuration.Intents.HasValue)
            {
                this.Logger.LogDebug(LoggerEvents.Intents, "Registered gateway intents ({0})", this.Configuration.Intents.Value);
            }
        }
コード例 #2
0
        /// <summary>
        /// Method to handle the first message from the Discord websocket
        /// </summary>
        /// <param name="helloResume">Gateway payload sent from the websocket</param>
        private async Task OnHelloMessageAsync(GatewayHello helloResume)
        {
            this._socketClient.StartHeartbeatTimer(helloResume.HeartbeatInterval);

            GatewayIdentify gatewayIdentify = new GatewayIdentify();

            _socketConfig         = JsonStorage.GetConfig();
            gatewayIdentify.Token = _socketConfig.Token;
            await this._socketClient.SendAsync(OpCodes.Identity, gatewayIdentify);
        }