feature: Decouple channel from messages #1901
Closed
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
With the arrival of Threads, some messages would be ignored as no known channel was found, I thought about two ways to fix this:
Since the first would make the library even more reliant on the cache, I decided to go with the 2nd, but this also comes with a heavy cost as the assumption of the channel being there is widely used internally as well, so I had to do several changes that might require a lot of changes by who's using the library.
Even now that channels are decoupled, the currently only known channel that could be missing are Threads (other guild channels are always cached and dms are created on the fly with only the user).
This is the first step on implementing threads for discord.net and this change will, at least, let bots process messages sent in those.
I'll leave this PR open for a few days so if anyone is interested, they can review or give feedback.
Possible changes before merging
context.Client.SendMessageAsync(channelId, ...
Changes
Changes done to the interface will also propagate to classes that implement them, obviously.
SendMessageAsync
(to send messages without the channel object, required forReplyAsync
)GetShardFor
andGetShardIdFor
overloads for ids are now publicAdded a
GuildId
property asulong?
Changed the
Channel
property fromIMessageChannel
toCacheable<IMessageChannel, ulong>
IsPrivate
now checks for the presence of a guild id instead of channel typeAdded a
GuildId
property asulong?
Changed the
Channel
property fromIMessageChannel
toCacheable<IMessageChannel, ulong>
GuildId
instead of channel typeGuildId
instead of channel typeThe example for the MessageReceived event was updated to not rely on the channel being present.