Use alternative endpoint to retrieve threads when requested by a bot (#1037)

Co-authored-by: Oleksii Holub <1935960+Tyrrrz@users.noreply.github.com>
This commit is contained in:
William Unsworth
2023-05-24 10:02:34 -06:00
committed by GitHub
parent 6bbde4ccdc
commit 41b4e47d0e
3 changed files with 78 additions and 38 deletions

View File

@@ -36,6 +36,12 @@ public class GetChannelsCommand : DiscordCommandBase
.ThenBy(c => c.Name)
.ToArray();
var threads = IncludeThreads
? (await Discord.GetGuildThreadsAsync(GuildId, cancellationToken))
.OrderBy(c => c.Name)
.ToArray()
: Array.Empty<ChannelThread>();
foreach (var channel in channels)
{
// Channel ID
@@ -51,31 +57,24 @@ public class GetChannelsCommand : DiscordCommandBase
using (console.WithForegroundColor(ConsoleColor.White))
await console.Output.WriteLineAsync($"{channel.Category.Name} / {channel.Name}");
if (IncludeThreads)
foreach (var thread in threads.Where(t => t.ParentId == channel.Id))
{
var threads = (await Discord.GetChannelThreadsAsync(channel.Id, cancellationToken))
.OrderBy(c => c.Name)
.ToArray();
// Indent
await console.Output.WriteAsync('\t');
foreach (var thread in threads)
{
// Indent
await console.Output.WriteAsync('\t');
// Thread ID
await console.Output.WriteAsync(
thread.Id.ToString().PadRight(18, ' ')
);
// Thread ID
await console.Output.WriteAsync(
thread.Id.ToString().PadRight(18, ' ')
);
// Separator
using (console.WithForegroundColor(ConsoleColor.DarkGray))
await console.Output.WriteAsync(" | ");
// Separator
using (console.WithForegroundColor(ConsoleColor.DarkGray))
await console.Output.WriteAsync(" | ");
// Thread name
using (console.WithForegroundColor(ConsoleColor.White))
await console.Output.WriteLineAsync($"Thread / {thread.Name}");
}
}
// Thread name
using (console.WithForegroundColor(ConsoleColor.White))
await console.Output.WriteLineAsync($"Thread / {thread.Name}");
}
}
}
}