Skip to content

Implemented Threads (Draft)

Mateusz Brawański requested to merge github/fork/DWaffles/threads into master

Created by: DWaffles

Summary

This is WIP PR for implementation of threads. Discord API documentation is at times wrong or currently in the middle of being PR'd to fix, but I will continue working on this. PR'ing this so I can get feedback. This is still somewhat of a rough WIP so there are a few loose comments that will be removed. This brings the lib up API v9 to note.

I've been using these commands to test the changes if you wish to see how someone can programmatically use threads.

Details

The implementation of this method is that DiscordThreadChannel extends DiscordChannel, allowing easy integration with the rest of the library with small changes. To use thread methods, a DiscordChannel just needs to be to casted to a DiscordThreadChannel. For commands next, the DiscordChannel overload works properly with this.

Thread cache has been implemented and it is the goal that all active threads will be cached. I am still trying to test edge cases. How this is implemented is that DiscordGuild has a _threads property. I make the assumption that all active threads will be cached, as this is how Discord seems to do things.

I also make the assumption that guild features are always properly cached which they should be, this is to check if people can create private threads or use the three and seven day archive options.

Changes

Added Events

  • ThreadCreated
  • ThreadUpdated
  • ThreadDeleted
  • ThreadListSynced
  • ThreadMemberUpdated
  • ThreadMembersUpdated

Endpoints

  • Start Thread with Message
  • Start Thread without Message
  • Join Thread
  • Leave Thread
  • Add Thread Member
  • Remove Thread Member
  • List Thread Members
  • List Active Threads
  • List Public Archived Threads
  • List Private Archived Threads
  • List Joined Private Archived Threads

Modified Discord Entities & Stuff

DiscordGuild

  • Threads property & _threads
  • ListActiveThreadsAsync()

DiscordChannel

  • IsThread property
  • Threads property - using DiscordGuild's _threads
  • TriggerTypingAsync will not throw within thread channels
  • CreateThreadAsync() plus overloads

DiscordMessage

  • Channel property modified to work with threads
  • CreateThreadAsync()

Other

  • ChannelType enum has new thread types
  • GetChannelAsync() will return a thread object as a DiscordChannel if the channel is type thread

New Discord Entities & Stuff

DiscordThreadChannel

  • CurrentMember refers to the bot. If the bot has joined the thread, this will have a value
  • JoinThreadAsync(), LeaveThreadAsync(), ListJoinedMembersAsync(), AddThreadMemberAsync(), RemoveThreadMemberAsync()

Other

  • DiscordThreadMetadata DiscordThreadMember have base their properties from the API
  • AutoArchiveDuration representing... the... auto archive duration of a channel.
  • RestThreadCreatePayload

Still To-Do

  • Create flags enum
  • Thread edit capabilities
  • Document/add checks on DiscordChannel methods that will fail/throw when it's a threads
  • Properly test/document exceptions for new methods
  • Audit log stuff for threads
  • Do all that fancy operator overloading for created entities

Notes

  • I can no longer test any features locked behind nitro boosts.
  • Regarding thread member update, @ajpalkovic: "this event is documented for completeness, but unlikely to be used by most bots. For bots, this event largely is just a signal that you are a member of the thread." So it's here for completeness. I have no idea when it's called anyway. Whenever the bot is added or removed from a thread, thread members gets called.
  • If anyone can advise on how to better access member objects than the current way, let me know.

Merge request reports

Loading