Skip to content

Commit 0fd3415

Browse files
committed
Handle channels being created or destroyed
1 parent b9d103e commit 0fd3415

File tree

1 file changed

+15
-3
lines changed

1 file changed

+15
-3
lines changed

src/DevChatter.Bot.Infra.Discord/DiscordChatClient.cs

+15-3
Original file line numberDiff line numberDiff line change
@@ -31,25 +31,37 @@ public DiscordChatClient(DiscordClientSettings settings)
3131
_discordClient.MessageReceived += DiscordClientMessageReceived;
3232
_discordClient.GuildAvailable += DiscordClientGuildAvailable;
3333
_discordClient.GuildUnavailable += DiscordClientGuildUnavailable;
34+
_discordClient.ChannelCreated += DiscordClientChannelCreated;
35+
_discordClient.ChannelDestroyed += DiscordClientChannelDestroyed;
3436
_discordClient.UserJoined += DiscordClientUserJoined;
3537
_discordClient.UserLeft += DiscordClientUserLeft;
3638
}
3739

38-
private async Task DiscordClientGuildAvailable(SocketGuild arg)
40+
private async Task DiscordClientGuildAvailable(SocketGuild guild)
3941
{
40-
_Guild = arg;
42+
_Guild = guild;
4143
_GuildChannelIds.AddRange(_Guild.Channels.Select(channel => channel.Id));
4244
_TextChannel = _Guild.Channels.FirstOrDefault(channel => channel.Id == _settings.DiscordTextChannelId) as ISocketMessageChannel;
4345
_isReady = true;
4446
}
4547

46-
private async Task DiscordClientGuildUnavailable(SocketGuild arg)
48+
private async Task DiscordClientGuildUnavailable(SocketGuild guild)
4749
{
4850
_Guild = null;
4951
_GuildChannelIds.Clear();
5052
_isReady = false;
5153
}
5254

55+
private async Task DiscordClientChannelCreated(SocketChannel newChannel)
56+
{
57+
_GuildChannelIds.Add(newChannel.Id);
58+
}
59+
60+
private async Task DiscordClientChannelDestroyed(SocketChannel oldChannel)
61+
{
62+
_GuildChannelIds.Remove(oldChannel.Id);
63+
}
64+
5365
private async Task DiscordClientMessageReceived(SocketMessage arg)
5466
{
5567
var message = arg as SocketUserMessage;

0 commit comments

Comments
 (0)