Add before and after execute async (#1998)
This commit is contained in:
@@ -311,6 +311,7 @@ namespace Discord.Interactions.Builders
|
|||||||
|
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
|
await instance.BeforeExecuteAsync(commandInfo).ConfigureAwait(false);
|
||||||
instance.BeforeExecute(commandInfo);
|
instance.BeforeExecute(commandInfo);
|
||||||
var task = commandInvoker(instance, args) ?? Task.Delay(0);
|
var task = commandInvoker(instance, args) ?? Task.Delay(0);
|
||||||
|
|
||||||
@@ -332,6 +333,7 @@ namespace Discord.Interactions.Builders
|
|||||||
}
|
}
|
||||||
finally
|
finally
|
||||||
{
|
{
|
||||||
|
await instance.AfterExecuteAsync(commandInfo).ConfigureAwait(false);
|
||||||
instance.AfterExecute(commandInfo);
|
instance.AfterExecute(commandInfo);
|
||||||
( instance as IDisposable )?.Dispose();
|
( instance as IDisposable )?.Dispose();
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,3 +1,5 @@
|
|||||||
|
using System.Threading.Tasks;
|
||||||
|
|
||||||
namespace Discord.Interactions
|
namespace Discord.Interactions
|
||||||
{
|
{
|
||||||
/// <summary>
|
/// <summary>
|
||||||
@@ -11,12 +13,24 @@ namespace Discord.Interactions
|
|||||||
/// <param name="context"></param>
|
/// <param name="context"></param>
|
||||||
void SetContext (IInteractionContext context);
|
void SetContext (IInteractionContext context);
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Method body to be executed asynchronously before executing an application command.
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="command">Command information related to the Discord Application Command.</param>
|
||||||
|
Task BeforeExecuteAsync(ICommandInfo command);
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Method body to be executed before executing an application command.
|
/// Method body to be executed before executing an application command.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="command">Command information related to the Discord Application Command.</param>
|
/// <param name="command">Command information related to the Discord Application Command.</param>
|
||||||
void BeforeExecute(ICommandInfo command);
|
void BeforeExecute(ICommandInfo command);
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Method body to be executed asynchronously after an application command execution.
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="command">Command information related to the Discord Application Command.</param>
|
||||||
|
Task AfterExecuteAsync(ICommandInfo command);
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Method body to be executed after an application command execution.
|
/// Method body to be executed after an application command execution.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
|
|||||||
@@ -20,6 +20,12 @@ namespace Discord.Interactions
|
|||||||
/// <inheritdoc/>
|
/// <inheritdoc/>
|
||||||
public virtual void BeforeExecute (ICommandInfo command) { }
|
public virtual void BeforeExecute (ICommandInfo command) { }
|
||||||
|
|
||||||
|
/// <inheritdoc/>
|
||||||
|
public virtual Task BeforeExecuteAsync(ICommandInfo command) => Task.CompletedTask;
|
||||||
|
|
||||||
|
/// <inheritdoc/>
|
||||||
|
public virtual Task AfterExecuteAsync(ICommandInfo command) => Task.CompletedTask;
|
||||||
|
|
||||||
/// <inheritdoc/>
|
/// <inheritdoc/>
|
||||||
public virtual void OnModuleBuilding (InteractionService commandService, ModuleInfo module) { }
|
public virtual void OnModuleBuilding (InteractionService commandService, ModuleInfo module) { }
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user