InvalidCastException when converting DiscordUser to DiscordMember
See original GitHub issueSummary
System.InvalidCastException when trying to cast DiscordUser
to DiscordMember
Details
.NET 5.0 Windows 10 DSharpPlus 4.0.0
[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)
Steps to reproduce
Add event to Client.VoiceStateUpdated
, convert DiscordUser
to DiscordMember
using VoiceStateUpdateEventArgs
property After
and finally property User
.
private Task OnVoiceState(DiscordClient sender, VoiceStateUpdateEventArgs e)
{
var member = (DiscordMember) e.After.User;
Console.WriteLine(member.Nickname);
return Task.CompletedTask;
}
Notes
It’s working like 50% of the time when i join or leave a channel it throws an error but when my friend joins it works. Funny thing that yesterday it didnt work with both of us.
Issue Analytics
- State:
- Created 2 years ago
- Comments:5 (3 by maintainers)
Top Results From Across the Web
Converting DiscordUser to DiscordMember
InvalidCastException : Unable to cast object of type 'DSharpPlus.Entities.DiscordUser' to type 'DSharpPlus.Entities.DiscordMember'. at dcBot.
Read more >CommandsNextExtension.cs
A .NET library for making bots using the Discord API. - DSharpPlus/DSharpPlus.CommandsNext/CommandsNextExtension.cs at master · DSharpPlus/DSharpPlus.
Read more >问题- 将DiscordUser 转换为DiscordMember - WhoseBug
InvalidCastException : Unable to cast object of type 'DSharpPlus.Entities.DiscordUser' to type 'DSharpPlus.Entities.DiscordMember'. at dcBot.Run.Bot.
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
Okay so i added this to my discord configuration
Intents = DiscordIntents.All,
and enabled these 2 checksAND IT WORKED, thanks for help
Do you have the proper intents enabled on your dashboard and
DiscordConfiguration
? When I had my guild member and presence intents enabled I had no issues, however the moment I turned them off I started to receive this exception.