Skip to content

Instantly share code, notes, and snippets.

@Chris-Johnston
Created March 28, 2018 10:24
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Chris-Johnston/0dc231b1a523d04865a838764e0b5e53 to your computer and use it in GitHub Desktop.
Save Chris-Johnston/0dc231b1a523d04865a838764e0b5e53 to your computer and use it in GitHub Desktop.
Sample code for SocketTextChannel and SocketVoiceChannel categories
// Sample code for showing that SocketCategoryChannel, SocketTextChannel and SocketVoiceChannel work correctly
// with categories
// Use this with a test guild that contains some categories with nested text channels and voice channels
// Should just print out all of the nested channels (and their matching parent categories)
// and end with "done"
// not a great automated test, but useful for ensuring that it doesn't crash
private async Task Client_GuildAvailable1(SocketGuild arg)
{
if (arg.Id == 428476681519497218)
{
var cat1 = arg.GetChannel(428476681519497219) as SocketCategoryChannel;
Console.WriteLine($"{cat1.Name}");
foreach(var subChan in cat1.Channels)
{
Console.WriteLine($"{subChan.Name} - {subChan.Id}");
if(subChan is SocketTextChannel)
{
var text = subChan as SocketTextChannel;
var cat = await text.GetCategoryAsync();
Console.WriteLine(cat?.Name);
}
if (subChan is SocketVoiceChannel)
{
var voice = subChan as SocketVoiceChannel;
var cat = await voice.GetCategoryAsync();
Console.WriteLine(cat.Name);
}
if (subChan is INestedChannel)
{
var n = subChan as INestedChannel;
var cat = await n.GetCategoryAsync();
Console.WriteLine(cat.Name);
Console.WriteLine(n.CategoryId);
}
}
cat1 = arg.GetChannel(428476681519497221) as SocketCategoryChannel;
Console.WriteLine($"{cat1.Name}");
foreach (var subChan in cat1.Channels)
{
Console.WriteLine($"{subChan.Name} - {subChan.Id}");
}
Console.WriteLine("done");
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment