Erisa/Cliptok

Todo: Delete forum threads when the only message is deleted

Closed this issue · 0 comments

Erisa commented

For fun, I asked chatgpt to write it. It may have got it wrong but this is roughly what i wanted

private async Task OnMessageDeleted(DiscordClient client, MessageDeleteEventArgs e)
{
    var channel = e.Channel;

    // Check if the channel is a thread and has any messages left
    if (channel.Type == ChannelType.Thread && channel is DiscordThreadChannel threadChannel)
    {
        var messages = await threadChannel.GetMessagesAsync(1);
        if (messages.Count == 0)
        {
            await threadChannel.DeleteAsync();
        }
    }
}