#Scoped Slash Commands

1 messages · Page 1 of 1 (latest)

polar thistle
#

My attempt at making slash commands consume scoped dependencies doesn't seem to work

#
        private async Task OnInteractionCreated(SocketInteraction interaction)
        {
            // Message components have a seperate event listener
            if (interaction.Type == InteractionType.MessageComponent) return;

            var ctx = new DiscordInteractionContext(_bot, interaction, _serviceProvider);

            var result = await _service.ExecuteCommandAsync(ctx, _serviceProvider);

            await OnPostInteractionAsync(result, ctx);
        }
        private async Task AddModulesAsync()
        {
            using var scope = _serviceProvider.CreateScope();

            var modules = await _service.AddModulesAsync(Assembly.GetEntryAssembly(), scope.ServiceProvider);

            await _service.AddModulesToGuildAsync(DiscordConstants.TestGuildID, deleteMissing: true, modules.ToArray());
        }
#

Interactions come into the system but nothing happens. The result for the ExecuteCommandAsync is Success but no interaction method is invoked

#

The interaction service config has AutoServiceScopes as true which I would have though would handle all this for me but it throws when adding modules