Search code examples
c#.netdiscordbotsdsharp+

Commands don't pop up in tooltip


I just made my first Discord bot on C# using DSharpPlus, everything works fine, but the only thing is not okay, I can't the the bots commands in chat.

Please take a look on picture below and you will understand what im talking about.

In this window i must see /test command that i have in my bot code, but there is nothing here.(But command is working fine)

Image

There is my commands class:

public class TestCommands : BaseCommandModule
{
    [Command("test"), Description("test command")]
    public async Task Test(CommandContext ctx)
    {
        await ctx.Channel.SendMessageAsync($"Тестовое сообщение:\nПривет, {ctx.User.Username}");
    }
    [RequireRoles(RoleCheckMode.Any, "꧁ঔৣ死𝓐𝓹𝓮𝔁 𝓟𝓻𝓮𝓭𝓪𝓽𝓸𝓻ঔৣ꧂","Admin")]
    [Command("shutdown"), Description("Shutdown command")]
    public async Task Shutdown(CommandContext ctx)
    {
        await ctx.Channel.SendMessageAsync("Выключение...");
        Environment.Exit(0);
    }
}

Solution

  • You have created the Command Class, however, for Discord to be able to show it to the user, they need to be told about the command.

    To do this, I used the Documentation for DSharpPlus to shape my answer. https://dsharpplus.github.io/DSharpPlus/articles/slash_commands.html

    "Slash commands can be registered either globally or for a certain guild. However, if you try to register them globally, they can take up to an hour to cache across all guilds. So, it is recommended that you only register them for a certain guild for testing, and only register them globally once they're ready to be used." - DSharpPlus Documentation

    You will need to add the following code to your bot class:

    using DSharpPlus.SlashCommands;
    var slash = discord.UseSlashCommands();
    
    // Use guild-specific deployments for testing, they are instant.
    slash.RegisterCommands<SlashCommands>(guild_id);
    
    // Use global deployments for production, they take up to an hour to go everywhere.
    slash.RegisterCommands<SlashCommands>();
    

    I have also attached an example of a Slash Command, if you were to adapt your code to follow the same format it will allow the SlashCommand to be registered.

    [SlashCommand("test", "A slash command made to test the DSharpPlus Slash Commands extension!")]
    public async Task TestCommand(InteractionContext ctx)
    {
        await ctx.CreateResponseAsync(InteractionResponseType.ChannelMessageWithSource, new DiscordInteractionResponseBuilder().WithContent("Success!"));
    }