From 9348e087b016acd87721fbb69ce0588f598d1bb4 Mon Sep 17 00:00:00 2001 From: Christopher F Date: Sat, 30 Jul 2016 18:23:12 -0400 Subject: [PATCH] Don't load modules that are already loaded Previously, if a user autoloaded commands more than once, commands that were already in the command map would be readded. If the module list already contains a module with the same type as the module being loaded, it will not load the new instance of this module. --- src/Discord.Net.Commands/CommandService.cs | 3 +++ 1 file changed, 3 insertions(+) diff --git a/src/Discord.Net.Commands/CommandService.cs b/src/Discord.Net.Commands/CommandService.cs index cd09c47b6..cc01ca2be 100644 --- a/src/Discord.Net.Commands/CommandService.cs +++ b/src/Discord.Net.Commands/CommandService.cs @@ -117,6 +117,9 @@ namespace Discord.Commands } private Module LoadInternal(object moduleInstance, ModuleAttribute moduleAttr, TypeInfo typeInfo) { + if (_modules.Any(m => m.Key.GetType().GetTypeInfo() == typeInfo)) + return _modules.FirstOrDefault(m => m.Key.GetType().GetTypeInfo() == typeInfo).Value; + var loadedModule = new Module(this, moduleInstance, moduleAttr, typeInfo); _modules[moduleInstance] = loadedModule;