Remora.Discord icon indicating copy to clipboard operation
Remora.Discord copied to clipboard

[Bug]: Nested command groups causes un-nested registrations

Open VelvetToroyashi opened this issue 1 year ago • 3 comments

Description

When registering a nested slash command group, the child group is un-nested at runtime.

Steps to Reproduce

Register the following with Remora.Discord.Commands

[Group("parent")]
public class ParentGroup : CommandGroup
{
  [Group("child")]
  public class ChildGroup : CommandGroup
  {
    [Command("command")]
    public async Task<Result> CommandAsync() => Result.FromSuccess();
  }
}

Expected Behavior

The command is registered with discord as `/parent child command.

This is represented as Command ➜ Subcommand-group ➜ Subcommand

Current Behavior

The command is in fact registered in this manner, but is also duplicated, eliding the parent.

This is illustrated in this screenshot: image

Top: Command ➜ Subommand (Incorrect) Bottom: Command ➜ Subcommand-group ➜ Command (Correct)

This is a bug in Remora's translation from Command tree ➜ Application command tree, however executing the malformed command still appears to work correctly

Library / Runtime Information

C# 11 .NET 7.0.2 Remora.Discord.Commands 26.2.3

VelvetToroyashi avatar Apr 14 '23 01:04 VelvetToroyashi

I don't think this is a Remora issue, because I have several groups with this setup that work just fine. Make sure you're not registering the inner group by itself, either explicitly or via assembly scanning.

Nihlus avatar Apr 14 '23 08:04 Nihlus

Hmm. Seems to be an issue with the assembly scanning code, since there isn't a check for nested children in groups

https://github.com/Remora/Remora.Discord/blob/3818e52/Remora.Discord.Extensions/Extensions/ServiceCollectionExtensions.cs#L71-L77

VelvetToroyashi avatar Apr 14 '23 08:04 VelvetToroyashi

Also following up on this (has it really been three days already?), I can confirm that adding t => !t.IsNested as a type filter works image

Thank goodness making extensible APIs.

VelvetToroyashi avatar Apr 17 '23 07:04 VelvetToroyashi