Add support for void-returning commands
This commit is contained in:
@@ -252,7 +252,7 @@ namespace Discord.Commands
|
|||||||
private static bool IsValidCommandDefinition(MethodInfo methodInfo)
|
private static bool IsValidCommandDefinition(MethodInfo methodInfo)
|
||||||
{
|
{
|
||||||
return methodInfo.IsDefined(typeof(CommandAttribute)) &&
|
return methodInfo.IsDefined(typeof(CommandAttribute)) &&
|
||||||
methodInfo.ReturnType == typeof(Task) &&
|
(methodInfo.ReturnType == typeof(Task) || methodInfo.ReturnType == typeof(void)) &&
|
||||||
!methodInfo.IsStatic &&
|
!methodInfo.IsStatic &&
|
||||||
!methodInfo.IsGenericMethod;
|
!methodInfo.IsGenericMethod;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,13 +1,13 @@
|
|||||||
|
using Discord.Commands.Builders;
|
||||||
using System;
|
using System;
|
||||||
using System.Linq;
|
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using System.Collections.Immutable;
|
using System.Collections.Immutable;
|
||||||
using System.Collections.Concurrent;
|
using System.Collections.Concurrent;
|
||||||
using System.Threading.Tasks;
|
|
||||||
using System.Reflection;
|
|
||||||
|
|
||||||
using Discord.Commands.Builders;
|
|
||||||
using System.Diagnostics;
|
using System.Diagnostics;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Reflection;
|
||||||
|
using System.Runtime.ExceptionServices;
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
|
||||||
namespace Discord.Commands
|
namespace Discord.Commands
|
||||||
{
|
{
|
||||||
@@ -166,10 +166,19 @@ namespace Discord.Commands
|
|||||||
}
|
}
|
||||||
catch (Exception ex)
|
catch (Exception ex)
|
||||||
{
|
{
|
||||||
ex = new CommandException(this, context, ex);
|
var originalEx = ex;
|
||||||
await Module.Service._cmdLogger.ErrorAsync(ex).ConfigureAwait(false);
|
while (ex is TargetInvocationException) //Happens with void-returning commands
|
||||||
|
ex = ex.InnerException;
|
||||||
|
|
||||||
|
var wrappedEx = new CommandException(this, context, ex);
|
||||||
|
await Module.Service._cmdLogger.ErrorAsync(wrappedEx).ConfigureAwait(false);
|
||||||
if (Module.Service._throwOnError)
|
if (Module.Service._throwOnError)
|
||||||
throw;
|
{
|
||||||
|
if (ex == originalEx)
|
||||||
|
throw;
|
||||||
|
else
|
||||||
|
ExceptionDispatchInfo.Capture(ex).Throw();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
await Module.Service._cmdLogger.VerboseAsync($"Executed {GetLogText(context)}").ConfigureAwait(false);
|
await Module.Service._cmdLogger.VerboseAsync($"Executed {GetLogText(context)}").ConfigureAwait(false);
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user