Throw a preemptive exception when sending presence data before connect
This prevents a later, less detailed nullref, when attempting to set the CurrentUser's presence data. This also removes a redundant CurrentUser assignment in the SetGameAsync method, since this will be set later on in the SendStatusAsync method.
This commit is contained in:
@@ -355,11 +355,12 @@ namespace Discord.WebSocket
|
|||||||
Game = new Game(name, streamUrl, streamType);
|
Game = new Game(name, streamUrl, streamType);
|
||||||
else
|
else
|
||||||
Game = null;
|
Game = null;
|
||||||
CurrentUser.Presence = new SocketPresence(Status, Game);
|
|
||||||
await SendStatusAsync().ConfigureAwait(false);
|
await SendStatusAsync().ConfigureAwait(false);
|
||||||
}
|
}
|
||||||
private async Task SendStatusAsync()
|
private async Task SendStatusAsync()
|
||||||
{
|
{
|
||||||
|
if (ConnectionState != ConnectionState.Connected)
|
||||||
|
throw new InvalidOperationException("Presence data cannot be sent while the client is disconnected.");
|
||||||
var game = Game;
|
var game = Game;
|
||||||
var status = Status;
|
var status = Status;
|
||||||
var statusSince = _statusSince;
|
var statusSince = _statusSince;
|
||||||
|
|||||||
Reference in New Issue
Block a user