'Get all threads in a guild Discord.net

I want to get all threads in a guild, what I did is the following

if (message.Author is SocketGuildUser socketUser)
{
    SocketGuild guild = socketUser.Guild;
    foreach (var channel in guild.Channels)
    {
        if(channel.GetType() == typeof())
        { 
            //Do code here
        }
    }
}

I got stuck at the typeof part, is It possible to detect if a channel is a thread? Thank you!



Solution 1:[1]

Yes, it is but you can simply use guild.ThreadChannels to get all thread channels in your guild.

Also GetType() is going to return you a data type which is being used for channels (SocketChannel). Method you are looking for is called GetChannelType() which returns an enum describing type of channel.

But in the if statement you posted you should just use

if(channel.GetChannelType() == ChannelType.PublicThread)

You have three types of threads.

  1. ChannelType.NewsThread
  2. ChannelType.PrivateThread
  3. ChannelType.PublicThread

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Hantick