#DescriptionAttribute and DefaultCommandAttribute does not seem to do anything

1 messages · Page 1 of 1 (latest)

topaz sorrel
#
    [Command("register")]
    [Description("Allows user to register use !register yoursteamidhere")]

that description does not show if I find the command in the context, and output description like this:

        var commands = await ctx.Client.GetGlobalApplicationCommandsAsync();
        var commandList = string.Join("\n", commands.Select(c => $"{c.Name}: {c.Description}"));
        await ctx.RespondAsync($"Available commands:\n{commandList}");

Also when trying to use
[DefaultCommand] on a subcommand, it does not seem to work anymore, is there some setting I have not enabled while setting up the bot?

#

I am using latest nightly

#

In the same vein, Command overloads doesnt work anymore I believe (have not tested since 4.5.1 with that)

wise stump
#

DefaultGroupCommand doesn't work on slash commands, discord restriction

#

and yes overloads are currently unsupported

#

which is why CommandsNext, which supports overloads, isn't deprecated yet

topaz sorrel
#

using DefaultGroupCommand on text command, but I have not disabled slash command, so that may be it

wise stump
#

how are you applying it?

#

iirc the default group command currently also needs a CommandAttribute

topaz sorrel
#
[Command("ruleSet")]
public class RuleSetCommands : IDiscordCommandHandler
{
    private readonly ICommandCache _commandCache;
    private readonly IMediator _mediator;

    public RuleSetCommands(ICommandCache commandCache, IMediator mediator)
    {
        _commandCache = commandCache;
        _mediator = mediator;
    }


    [ActiveLeague]
    [DefaultGroupCommand]
    public async Task GetChannelRules(CommandContext ctx)
    {
        if (_commandCache.RuleSet == null) return;
        await ctx.Channel.SendMessageAsync(_commandCache.RuleSet!.ToDiscord());
    }
#

when writing !ruleSet, the expectation is that GetChannelRules should run

topaz sorrel
#

oh so

    [Command("banana")]
    [DefaultGroupCommand]
#

for description I use
using System.ComponentModel;

#

[Description("Get the rules for the current channel")]

wise stump
#

full code and any potential logs, please

topaz sorrel
#

I found that in another support article in here

#

ok DefaultGroupCommand works as intended if I have a [Command("name")] on it as well

#

setting up proper test case for description now

#
using DSharpPlus.Commands;
using DSharpPlus.Commands.Trees.Metadata;
using DSharpPlus.Entities;
using MediatR;
using System.ComponentModel;
using Zoctai.Dropshot.Discord.Abstractions;

namespace Zoctai.Dropshot.Discord.Commands;

[Command("test")]
[Description("Test commands for Discord components and threads")]
public class TestCommands : IDiscordCommandHandler
{
    private readonly IMediator _mediator;

    public TestCommands(IMediator mediator)
    {
        _mediator = mediator;
    }

    [Command("buttons")]
    [Description("here is description")]
    [DefaultGroupCommand]
    public async Task CreateButtons(CommandContext ctx)
    {
        var buttonsRow = new DiscordActionRowComponent([
            new DiscordButtonComponent(DiscordButtonStyle.Primary, "1_top_d", "Blurple!"),
            new DiscordButtonComponent(DiscordButtonStyle.Secondary, "2_top_d", "Grey!"),
            new DiscordButtonComponent(DiscordButtonStyle.Success, "3_top_d", "Green!"),
            new DiscordButtonComponent(DiscordButtonStyle.Danger, "4_top_d", "Red!"),
        ]);

        var builder = new DiscordMessageBuilder().EnableV2Components().AddActionRowComponent(buttonsRow).AddTextDisplayComponent("sick content yo");

        await ctx.Channel.SendMessageAsync(builder);

    }
}
#

when I run

using DSharpPlus.Commands;
using System.ComponentModel;
using Zoctai.Dropshot.Discord.Abstractions;

namespace Zoctai.Dropshot.Discord.Commands;
public class BasicCommands : IDiscordCommandHandler
{
    [Command("commands")]
    [Description("List all available commands")]
    public async Task ShowCommands(CommandContext ctx)
    {
        var commands = await ctx.Client.GetGuildApplicationCommandsAsync(ctx.Guild.Id);
        var commandList = string.Join("\n", commands.Select(c => $"{c.Name}: {c.Description}"));
        await ctx.RespondAsync($"Available commands:\n{commandList}");
    }
}

in my channel I get:
test: No description provided.

but I suspect its me not traversing this correctly when looking at it more now

#

the verbose logs only say:

DiscordClient: [14:20:00 DBUG] Adding command from type Zoctai.Dropshot.Discord.Commands.SignupCommands
DiscordClient: [14:20:00 DBUG] Adding command from type Zoctai.Dropshot.Discord.Commands.SignupCommands
DiscordClient: [14:20:00 DBUG] Adding command from type Zoctai.Dropshot.Discord.Commands.SignupCommands
DiscordClient: [14:20:00 DBUG] Adding command from type Zoctai.Dropshot.Discord.Commands.SignupCommands
DiscordClient: [14:20:00 DBUG] Adding command from type Zoctai.Dropshot.Discord.Commands.TestCommands
#

here is the actual commands list I found in the verbose logs

RestClient: [14:20:06 VERB] Request ID:01JYBS9R8957E4TYMETG6V4HRQ: Route has no known hash: applications/:application_id/commands.
RestClient: [14:20:06 VERB] Request ID:01JYBS9R8957E4TYMETG6V4HRQ - Initial bucket capacity: 1000

response from that

#

fetching the commands does not show all the commands either, and there is different, but overlapping set if i use await client.GetGuildApplicationCommandsAsync(ctx.Guild!.Id) vs await client.GetGlobalApplicationCommandsAsync()

#

If I had to hazard a wild ass guess, its only listing commands that is allowed as slash commands, and that normal text commands only remains on my bot client, but it only fetches commands from discords api's so there is a mismatch

wise stump
topaz sorrel
#

found it

#

It checks for the CommandsNext description attribute, not the ComponentModel Description attribute

wise stump
#

that's because you're in CommandsNext code

topaz sorrel
#

yeah I know, i got linked there

#

from CommandBuilder

wise stump
#

because github doesn't actually know how C# works, it just does a naive text + regex search

topaz sorrel
#

ah

wise stump
#

CommandBuilder cannot reference CommandsNext

topaz sorrel
#

meh, thought I was smart for a second

#

I see its using ComponentsModel now

wise stump
#

if you inspect it in your IDE it should link to the proper one

topaz sorrel
#

maybe its something with the local commands not getting pushed correctly then, how do I list all the "local" commands?

wise stump
#

CommandsExtension.Commands

topaz sorrel
#
public class BasicCommands(CommandsExtension cmds) : IDiscordCommandHandler
{
    [Command("commands")]
    [Description("List all available commands")]
    public async Task ShowCommands(CommandContext ctx)
    {
        
        var commandList = string.Join("\n", cmds.Commands.Select(kv => $"{kv.Key}: {kv.Value.Description}"));
        await ctx.RespondAsync($"Available commands:\n{commandList}");
    }
}
#

that gave more success

#
unSign: 
test: this is a test description
ruleSet: No description provided.
rules: 
commands: List all available commands
resetChannel: 
unregister: 
player: No description provided.
ready: 
sign: 
admin: No description provided.
find: 
accept: 
pick: 
challenge: challenge a player
info: 
list: 
maps: 
games: 
decline: 
whois: 
whoami: 
cancel: 
stack: 
register: Allows user to register use !register yoursteamidhere
wise stump
#

in your setup code, try registering a SlashCommandProcessor with the overwrite commands setting set to true in its configuration

#

by default it calculates which ones have changed and then only registers the changes

topaz sorrel
#
            SlashCommandProcessor slashCommandProcessor = new(new SlashCommandConfiguration
            {
                UnconditionallyOverwriteCommands = true
            });

            extension.AddProcessor(textCommandProcessor);
            extension.AddProcessor(slashCommandProcessor);
#

like that, testing now

#

no change, still shows no descriptions, ill check if there is some cache that needs to be purged, going for a run, and will check in an hour

#

using the CommandsExtension is what I actually was after though

wise stump
topaz sorrel
#

but the problem turned interesting

#

I both ctrl+r and hard shutdown adn restart

#

ok, got a change now

BaseCommandProcessor: [15:33:07 EROR] Could not build valid application commands, cancelling application command registration.
System.InvalidOperationException: No converter found for parameter type 'Guid'
   at DSharpPlus.Commands.Processors.SlashCommands.SlashCommandProcessor.ToApplicationParameterAsync(Command command, CommandParameter parameter, Int32 i)
   at DSharpPlus.Commands.Processors.SlashCommands.SlashCommandProcessor.PopulateVariadicParametersAsync(Command command, List`1 options)
   at DSharpPlus.Commands.Processors.SlashCommands.SlashCommandProcessor.ToApplicationParameterAsync(Command command, Int32 depth)
   at DSharpPlus.Commands.Processors.SlashCommands.SlashCommandProcessor.ToApplicationParameterAsync(Command command)
   at DSharpPlus.Commands.Processors.SlashCommands.SlashCommandProcessor.ToApplicationCommandAsync(Command command)
   at DSharpPlus.Commands.Processors.SlashCommands.SlashCommandProcessor.RegisterSlashCommandsAsync(CommandsExtension extension)
#

which tells me that I have not pushed slash commands for a looooong time befoer adding the slashcommandsprocessor just now

wise stump
#

oh dear, variadics

topaz sorrel
#

maybe slash commands error simply have been swallowed because i didnt have the processor, ever since I added a command that used guid

#

which was relatively recently... afaik

#

and there we go, remove Guid, pass in string, and we get register: Allows user to register use !register yoursteamidhere

#

so simply I was not registering A slashcommandprocessor for a good while because at some point I had apparently set: RegisterDefaultCommandProcessors = false,

wise stump
#

that would do it

topaz sorrel
#

in other words: I am a moron, but I learned that I want to use CommandsExtension for what I want to do