From 0d74c5cc629e0bb176734a5f2350ecef04de3a94 Mon Sep 17 00:00:00 2001 From: Cenk Ergen <57065323+Cenngo@users.noreply.github.com> Date: Sat, 30 Apr 2022 04:37:22 +0300 Subject: [PATCH] fix: Implement fix for Custom Id Segments NRE (#2274) --- src/Discord.Net.Interactions/InteractionService.cs | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/src/Discord.Net.Interactions/InteractionService.cs b/src/Discord.Net.Interactions/InteractionService.cs index 8eb5799d6..24302dfc7 100644 --- a/src/Discord.Net.Interactions/InteractionService.cs +++ b/src/Discord.Net.Interactions/InteractionService.cs @@ -834,11 +834,16 @@ namespace Discord.Interactions if (!searchResult.Command.SupportsWildCards || context is not IRouteMatchContainer matchContainer) return; - var matches = new RouteSegmentMatch[searchResult.RegexCaptureGroups.Length]; - for (var i = 0; i < searchResult.RegexCaptureGroups.Length; i++) - matches[i] = new RouteSegmentMatch(searchResult.RegexCaptureGroups[i]); + if (searchResult.RegexCaptureGroups?.Length > 0) + { + var matches = new RouteSegmentMatch[searchResult.RegexCaptureGroups.Length]; + for (var i = 0; i < searchResult.RegexCaptureGroups.Length; i++) + matches[i] = new RouteSegmentMatch(searchResult.RegexCaptureGroups[i]); - matchContainer.SetSegmentMatches(matches); + matchContainer.SetSegmentMatches(matches); + } + else + matchContainer.SetSegmentMatches(Array.Empty()); } internal TypeConverter GetTypeConverter(Type type, IServiceProvider services = null)