Skip to content
This repository was archived by the owner on Nov 24, 2022. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion TabletBot.Discord/LogExtensions.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using System.Threading.Tasks;
using System;
using System.Threading.Tasks;
using Discord;
using TabletBot.Common;
using LogMessage = Discord.LogMessage;
Expand Down
22 changes: 20 additions & 2 deletions TabletBot.Discord/Watchers/Commands/CommandMessageWatcher.cs
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,26 @@ public async Task Receive(IMessage message)
{
if (message.Content.StartsWith(_settings.CommandPrefix))
{
var context = new CommandContext(_discordClient, message as IUserMessage);
await _commandService.ExecuteAsync(context, 1, _serviceProvider).ConfigureAwait(false);
try
{
var context = new CommandContext(_discordClient, message as IUserMessage);
await _commandService.ExecuteAsync(context, 1, _serviceProvider).ConfigureAwait(false);
}
catch (Exception e)
{
Log.Exception(e);
try
{
string exMessage = e.GetType().FullName + ": " + e.Message;
await (message as IUserMessage).ReplyAsync(exMessage);
}
catch (Exception respondEx)
{
Log.Exception(respondEx);
}

throw;
}
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,32 @@ IEnumerable<SlashCommandModule> commands

public async Task HandleInteraction(SocketInteraction interaction)
{
await Task.WhenAll(_commands.Select(m => m.HandleInteraction(interaction)));
try
{
await Task.WhenAll(_commands.Select(m => m.HandleInteraction(interaction)));
}
catch (Exception e)
{
Log.Exception(e);
try
{
string message = e.GetType().FullName + ": " + e.Message;
if (interaction.HasResponded)
{
await interaction.FollowupAsync(message, ephemeral: true);
}
else
{
await interaction.RespondAsync(message, ephemeral: true);
}
}
catch (Exception responseEx)
{
Log.Exception(responseEx);
}

throw;
}
}

public async Task InitializeAsync()
Expand Down