Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Bug]: Calling ChannelExtensions.GetChannelType on SocketForumChannel returns null #2502

Closed
3 tasks done
lapin-b opened this issue Oct 24, 2022 · 0 comments · Fixed by #2469
Closed
3 tasks done

[Bug]: Calling ChannelExtensions.GetChannelType on SocketForumChannel returns null #2502

lapin-b opened this issue Oct 24, 2022 · 0 comments · Fixed by #2469
Labels

Comments

@lapin-b
Copy link

lapin-b commented Oct 24, 2022

Check The Docs

  • I double checked the docs and couldn't find any useful information.

Verify Issue Source

  • I verified the issue was caused by Discord.Net.

Check your intents

  • I double checked that I have the required intents.

Description

Everything is in the title.

Calling ChannelExtensions.GetChannelType on SocketForumChannel returns null instead of ChannelType.Forum.

While I'm well aware that this method can return null because of the type annotation, I find strange that it doesn't handle the case of a SocketForumChannel.

Version

3.8.1

Working Version

No response

Logs

Stack trace from the sample code:

System.InvalidOperationException: Nullable object must have a value.
   at System.Nullable`1.get_Value()
   at bot.Modules.SynchronizationModule.ReadyHandler() in /home/l4p1n/Code/CLI/discord-bot/bot/Modules/SynchronizationModule.cs:line 38

The channel type the code crashes on is SocketForumChannel. Its contents is irrelevant for this report.

Sample

// Note: The prerequisite code to initialize a client has been cut out

// Replace zero with a real, existing forum channel ID.
ulong forumChannelId = 0;
// _client is a DiscordSocketClient
var forumChannel = _client.GetChannel(forumChannelId) as SocketForumChannel;
Console.WriteLine(
    $"Channel type number of channel ID {forumChannel.Name} " +
    $"is {(int)forumChannel.GetChannelType()}"
);

// The snippet throws an exception with a stack trace similar to the
// one provided in the "Logs" section

Packages

Not relevant. I can fill that in if requested.

@lapin-b lapin-b added the bug label Oct 24, 2022
Misha-133 added a commit to Misha-133/Discord.Net that referenced this issue Oct 25, 2022
@csmir csmir closed this as completed in 01ae904 Nov 7, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant