public async Task SetActivityAsync(DiscordActivity activity, int?pid = null)
        {
            var command = new DiscordCommand()
            {
                Command   = DiscordCommandType.SetActivity,
                Arguments = JObject.FromObject(new
                {
                    pid = pid.GetValueOrDefault(Process.GetCurrentProcess().Id),
                    activity
                })
            };

            var result = new DiscordFrame()
                         .WithType(DiscordFrameType.Frame)
                         .WithPayload(command)
                         .GetBytes();

            await this.RequireConnectedAsync().ConfigureAwait(false);

            await this.Pipe.WriteAsync(result, 0, result.Length).ConfigureAwait(false);
        }
        internal async Task SendCommandAsync(DiscordFrameType type, DiscordCommand command, DiscordCommandCallback callback = null)
        {
            if (this.Pipe == null || !this.Pipe.IsConnected)
            {
                return;
            }

            var result = new DiscordFrame()
                         .WithType(type)
                         .WithPayload(command)
                         .GetBytes();

            if (callback != null)
            {
                this.Callbacks.AddOrUpdate(command.Nonce, callback, (key, old) => callback);
            }

            await this.RequireConnectedAsync().ConfigureAwait(false);

            await this.Pipe.WriteAsync(result, 0, result.Length).ConfigureAwait(false);
        }
        protected async Task HandleEventAsync(DiscordFrame frame, DiscordCommand command)
        {
            switch (command.Event)
            {
            case DiscordEventType.Ready:
            {
                var e = command.Data.ToObject <ReadyEventArgs>();
                e.Client = this;

                this.Environment = e.Configuration;
                this.RpcVersion  = e.Version;
                this.CurrentUser = e.User;

                var handler = this.Ready;

                if (handler != null)
                {
                    await handler.Invoke(e).ConfigureAwait(false);
                }
            }
            break;
            }
        }