question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

InvalidCastException when converting DiscordUser to DiscordMember

See original GitHub issue

Summary

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:closed
  • Created 2 years ago
  • Comments:5 (3 by maintainers)

github_iconTop GitHub Comments

1reaction
ISmellYucommented, Apr 25, 2021

Okay so i added this to my discord configuration Intents = DiscordIntents.All, and enabled these 2 checks
image AND IT WORKED, thanks for help

1reaction
Neuheitcommented, Apr 25, 2021

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.

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found