From 5b63591ac4c3204c65c0925af897e3af652c06dc Mon Sep 17 00:00:00 2001 From: LtLi0n Date: Thu, 17 Oct 2019 20:28:53 +0300 Subject: [PATCH] Added a check before adding a module manually. Adding outer subtypes now seem to work, but they don't bind with parent modules properly yet. --- src/Discord.Net.Commands/CommandService.cs | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/src/Discord.Net.Commands/CommandService.cs b/src/Discord.Net.Commands/CommandService.cs index ad88a7b89..c93dec009 100644 --- a/src/Discord.Net.Commands/CommandService.cs +++ b/src/Discord.Net.Commands/CommandService.cs @@ -197,7 +197,13 @@ namespace Discord.Commands if (_typedModuleDefs.ContainsKey(type)) throw new ArgumentException("This module has already been added."); - var module = (await ModuleClassBuilder.BuildAsync(this, services, typeInfo).ConfigureAwait(false)).FirstOrDefault(); + bool isModuleType = await typeInfo.IsValidModuleType(logger: _cmdLogger); + if(!isModuleType) + { + throw new InvalidOperationException($"Type {typeInfo.FullName} cannot be transformed into a module. Look at the logs for more details."); + } + + var module = (await ModuleClassBuilder.BuildAsync(this, services, _typedModuleDefs, typeInfo).ConfigureAwait(false)).FirstOrDefault(); if (module.Value == default(ModuleInfo)) throw new InvalidOperationException($"Could not build the module {type.FullName}, did you pass an invalid type?");