我有 dsharp+ 的问题,所以基本上当我附加一个事件时
Client.VoiceStateUpdated += OnVoiceState;
private Task OnVoiceState(DiscordClient sender, VoiceStateUpdateEventArgs e)
{
var member = (DiscordMember) e.After.User;
Console.WriteLine(member.Nickname);
return Task.CompletedTask;
}
并尝试将其转换DiscordUser
为DiscordMember
它会引发异常,我知道我可以从文档中做到这一点
[Error] Exception occured
System.InvalidCastException: Unable to cast object of type 'DSharpPlus.Entities.DiscordUser' to type 'DSharpPlus.Entities.DiscordMember'.
at dcBot.Run.Bot.OnVoiceState(DiscordClient sender, VoiceStateUpdateEventArgs e) in C:\Users\lukas\RiderProjects\discord\bot\Run\Main.cs:line 219
at Emzi0767.Utilities.AsyncEvent`2.InvokeAsync(TSender sender, TArgs e, AsyncEventExceptionMode exceptionMode)
它有 50% 的时间在工作,当我加入频道或离开它时,它会抛出,但当我的朋友加入频道时它不会。这是怎么回事?