diff --git a/src/Discord.Net.Interactions/AutocompleteHandlers/AutocompleteHandler.cs b/src/Discord.Net.Interactions/AutocompleteHandlers/AutocompleteHandler.cs index 636ac840e3..a41298fc10 100644 --- a/src/Discord.Net.Interactions/AutocompleteHandlers/AutocompleteHandler.cs +++ b/src/Discord.Net.Interactions/AutocompleteHandlers/AutocompleteHandler.cs @@ -4,6 +4,7 @@ using System.Reflection; using System.Runtime.ExceptionServices; using System.Threading.Tasks; +using Microsoft.Extensions.DependencyInjection; namespace Discord.Interactions { @@ -29,6 +30,9 @@ protected virtual string GetLogString(IInteractionContext context) public Task ExecuteAsync(IInteractionContext context, IAutocompleteInteraction autocompleteInteraction, IParameterInfo parameter, IServiceProvider services) { + using IServiceScope scope = InteractionService._autoServiceScopes ? services?.CreateScope() : null; + services = InteractionService._autoServiceScopes ? scope?.ServiceProvider ?? EmptyServiceProvider.Instance : services; + switch (InteractionService._runMode) { case RunMode.Sync: @@ -44,7 +48,7 @@ public Task ExecuteAsync(IInteractionContext context, IAutocompleteInte default: throw new InvalidOperationException($"RunMode {InteractionService._runMode} is not supported."); } - + return Task.FromResult((IResult)ExecuteResult.FromSuccess()); }