#AddModuleAsync could not build the module

1 messages · Page 1 of 1 (latest)

mighty lark
#

I tried to make my own methods to add modules to IInteractionService, filtering by my custom attribute, but when it comes to AddModuleAsync I see System.InvalidOperationException: Could not build the module Geno.Commands.Other+BotCommands, did you pass an invalid type?

public static async Task AddPublicModules(this InteractionService service, Assembly assembly, IServiceProvider serviceProvider)
{
    foreach (var T in assembly.DefinedTypes)
    {
        if ((!T.IsPublic && !T.IsNestedPublic) || !typeof(IInteractionModuleBase).GetTypeInfo().IsAssignableFrom(T))
            continue;
            
        if (T.CustomAttributes.TryGetAttribute<MyAttribute>(out _))
            continue;

        await service.AddModuleAsync(T, serviceProvider).ConfigureAwait(false);
    }
}```
mighty lark
#

AddModuleAsync could not build the module

timber dune
#

does the type inherit modulebase

#

also you can call IsAssignableFrom without calling GetTypeInfo

mighty lark