discord-net/Discord.Net

[Bug]: ShardedInteractionContext.Channel NULL

Closed this issue · 5 comments

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

Within Thread-channels (regular threads, and forum threads), the channel property on the interaction context will return null always when the bot does not have admin permissions.

Here are the cases:

  • Occurs within thread channels when the bot does not have administrator permissions. If the bot had admin permissions beforehand, and executed within a thread, the bot will have all existing thread channels known, however, NRE will occur if a command is executed within a thread that was freshly created after the bot lost the permission, and then all subsequent thread channels that were cached previously will suddenly cease to exist.
  • This also occurs in events that take a socket interaction as an argument, the channel will be null but the channel ID will not.
    image
    image
  • Only occurs in thread channels created under "private channels", even though the bot does not complain about permissions regarding sending messages or responding to interactions.

Anymore information required, please request it.

Version

3.15.3

Working Version

No response

Logs

N/A, as it will throw a NullReferenceException anywhere that uses members such as ToString()

Sample

ShardedInteractionContext context = this.Context; // Within the confines of a Module.

var channelInfo = context.Channel.ToString(); // NRE when in a "private" thread and admin permission not enabled.

Packages

N/A

Environment

  • OS: Windows + Alpine Linux
  • Arch: x64
  • SDK: .NET SDK 8.0.303

This issue is being worked on within mfdlabs/grid-bot#335

New information:
This will not occur when using message content, as bots cannot see message dispatches within private threads.

A full channel object is not passed with the intraction and thus the property can be null. In those cases DNet tries to fallback to cache, but it may fail since only active public threads/active private treads bot was invited to will be synced on startup

A full channel object is not passed with the intraction and thus the property can be null. In those cases DNet tries to fallback to cache, but it may fail since only active public threads/active private treads bot was invited to will be synced on startup

So is this intentional? App commands can still be used within threads even if the bot wasn't invited to it.

Yes, that is intentional. The SocketInteractionContext.Channel property has a type of ISocketMessageChannel
thus, filling it with the partial data received with the interaction would be a breaking change, as that would require changing the type of the property to accept rest entities

You can try using Context.Interaction.InteractionChannel property instead since that one should always have the channel entity, either a cached one if available - or constructed from partial data sent along the interaction