Skip to content

Commit 4b7cda0

Browse files
authored
Fix IsTopLevelCommand (#2025)
* init * fix IsTopLevel for ModuleInfo and CommandInfo
1 parent 9594ccc commit 4b7cda0

File tree

2 files changed

+18
-3
lines changed

2 files changed

+18
-3
lines changed

src/Discord.Net.Interactions/Info/Commands/CommandInfo.cs

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ public abstract class CommandInfo<TParameter> : ICommandInfo where TParameter :
5050
public abstract bool SupportsWildCards { get; }
5151

5252
/// <inheritdoc/>
53-
public bool IsTopLevelCommand => IgnoreGroupNames || !Module.IsTopLevelGroup;
53+
public bool IsTopLevelCommand { get; }
5454

5555
/// <inheritdoc/>
5656
public RunMode RunMode { get; }
@@ -72,6 +72,7 @@ internal CommandInfo(Builders.ICommandBuilder builder, ModuleInfo module, Intera
7272
Name = builder.Name;
7373
MethodName = builder.MethodName;
7474
IgnoreGroupNames = builder.IgnoreGroupNames;
75+
IsTopLevelCommand = IgnoreGroupNames || CheckTopLevel(Module);
7576
RunMode = builder.RunMode != RunMode.Default ? builder.RunMode : commandService._runMode;
7677
Attributes = builder.Attributes.ToImmutableArray();
7778
Preconditions = builder.Preconditions.ToImmutableArray();
@@ -230,6 +231,20 @@ private async Task<IResult> ExecuteInternalAsync(IInteractionContext context, ob
230231
}
231232
}
232233

234+
private static bool CheckTopLevel(ModuleInfo parent)
235+
{
236+
var currentParent = parent;
237+
238+
while (currentParent != null)
239+
{
240+
if (currentParent.IsSlashGroup)
241+
return false;
242+
243+
currentParent = currentParent.Parent;
244+
}
245+
return true;
246+
}
247+
233248
// ICommandInfo
234249

235250
/// <inheritdoc/>

src/Discord.Net.Interactions/Info/ModuleInfo.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -115,7 +115,7 @@ internal ModuleInfo (ModuleBuilder builder, InteractionService commandService, I
115115
SubModules = BuildSubModules(builder, commandService, services).ToImmutableArray();
116116
Attributes = BuildAttributes(builder).ToImmutableArray();
117117
Preconditions = BuildPreconditions(builder).ToImmutableArray();
118-
IsTopLevelGroup = CheckTopLevel(parent);
118+
IsTopLevelGroup = IsSlashGroup && CheckTopLevel(parent);
119119
DontAutoRegister = builder.DontAutoRegister;
120120

121121
GroupedPreconditions = Preconditions.ToLookup(x => x.Group, x => x, StringComparer.Ordinal);
@@ -206,7 +206,7 @@ private static bool CheckTopLevel (ModuleInfo parent)
206206

207207
while (currentParent != null)
208208
{
209-
if (currentParent.IsTopLevelGroup)
209+
if (currentParent.IsSlashGroup)
210210
return false;
211211

212212
currentParent = currentParent.Parent;

0 commit comments

Comments
 (0)