Discord.Net
Discord.Net copied to clipboard
CommandService.AddTypeReader does not work properly
DayOfWeekReader is a TypeReader that parses to DayOfWeek objects. Discord.Commands provides a built-in reader for this; my implementation is capable of localization. When you attempt to add a TypeReader for a type already covered by built-in TypeReaders, currently you have to tell it not to replace the default, if you want it to replace the default.
commandService.AddTypeReader<DayOfWeek>(new DayOfWeekReader());
Expected result: A warning is logged and the custom DayOfWeekReader is added to the list, according to the documentation. Result: Custom DayOfWeekReader is not added to commandService.TypeReaders collection and no warning is logged.
commandService.AddTypeReader<DayOfWeek>(new DayOfWeekReader(), true);
Expected result: The custom DayOfWeekReader is added to the list and no warning is logged, according to the documentation. Result: Custom DayOfWeekReader is not added to commandService.TypeReaders collection.
commandService.AddTypeReader<DayOfWeek>(new DayOfWeekReader(), false);
Expected result: The result of this action is not documented. Does it throw an exception? Does it log a warning and do nothing? It doesn't say. Result: TypeReaders collection now contains the custom DayOfWeekReader and a NullableTypeReader<DayOfWeek>.
commandService.AddTypeReader<DayOfWeek>(new DayOfWeekReader(), true);Expected result: The custom DayOfWeekReader is added to the list and no warning is logged, according to the documentation. Result: Custom DayOfWeekReader is not added to commandService.TypeReaders collection.
Ah, I think I see the problem. When you replace a default reader, it gets added to _defaultTypeReaders, which isn't looked at by TypeReaders.