#double commands

1 messages · Page 1 of 1 (latest)

rugged condor
#

is it normal for discord to say I have two of the same command, even tho I only specified it once?

here is the command program:

namespace Markbot2._0
{
    public class SlashCommands : ApplicationCommandModule
    {
        [SlashCommand("test", "A slash command made to test the DSharpPlus Slash Commands extension!")]
        ...

        [SlashCommand("sum", "takes the sum of two numbers")]
        ...
        }

        [SlashCommand("8ball", "Ask Mark to provide his wisdom.")]
        ...
    }
}
+

annnnd my program.cs:

namespace Markbot2._0
{
    public class Program
    {
        static void Main(string[] args)
        {
            MainAsync().GetAwaiter().GetResult();
        }

        static async Task MainAsync()
        {

            var discord = new DiscordClient(new DiscordConfiguration()
            {
                Token = "i probably shouldn't hard code this",
                TokenType = TokenType.Bot,
                Intents = DiscordIntents.AllUnprivileged
            });

            var slash = discord.UseSlashCommands();

            slash.RegisterCommands<SlashCommands>(1050971027632558110);
            slash.RegisterCommands<SlashCommands>();

            await discord.ConnectAsync();

            Console.ForegroundColor = ConsoleColor.Green;
            Console.WriteLine("Bot online!");
            Console.ForegroundColor = ConsoleColor.White;

            Console.WriteLine("type 'exit' or press 'ctrl + c' twice to stop.");
            if (Console.ReadLine() == "exit")
            {
                System.Environment.Exit(1);
            }

            await Task.Delay(-1);
        }
    }
}
meager oriole
#
slash.RegisterCommands<SlashCommands>(1050971027632558110);
slash.RegisterCommands<SlashCommands>();
``` I believe this is your issue ![TE_VoHiYo](https://cdn.discordapp.com/emojis/649730904805081088.webp?size=128 "TE_VoHiYo")
#

You're registering the commands to both the guild and globally

rugged condor
#

knEw it ok ok thank u

meager oriole
#

No problem salute

#

What you could do

#

(And what I do)

#
#if DEBUG
slash.RegisterCommands<SlashCommands>(1050971027632558110);
#else
slash.RegisterCommands<SlashCommands>();
#endif
``` That way you're only making the correct API call and you're only doing it once
#

Completely up to you though

rugged condor
#

OHHH that's so smart what

#

thank u thank u i'll try that out :D

meager oriole
rugged condor
#

grahh sorry to say but i’m still having the same issue even tho i commited that change that only gave one command list register on DEBUG mode, im still having double commands rn

#

any idea what else it could be -?

hollow quail
#

you need to clear the registered commands

#

hans tag clear slash commands

covert pierBOT
# hollow quail hans tag clear slash commands

​​To clear slash commands, do one of the following:

➜ Use a tool like Insomnia (https://insomnia.rest), and PUT [] to api/v10/applications/:app_id/commands*
➜ Use BulkOverrideApplicationCommandsAsync on the DiscordClient**
➜ Use SlashCommandExtension#RegisterCommands<ApplicationCommandModule>()***
➜ Use curl: curl -H "Authorization: Bot <token>" -H "Content-Type: application/json" -X PUT --data-raw "[]" "https://discord.com/api/v10/applications/:app_id/commands"

* For guild guild commands, use api/v10/applications/:app_id/guilds/:guild_id/commands instead.
** For guild commands, use BulkOverrideGuildApplicationCommandsAsync
*** For guild commands, pass the ID of your guild.

:app_id and :guild_id are placeholders for actual IDs.

If you're using the third route, you must start the client for it to take effect.

rugged condor
#

I’m really unsure on how to proceed with that, not exactly sure what a rest is ;-; i’ll go research that rn

meager oriole
# rugged condor I’m really unsure on how to proceed with that, not exactly sure what a rest is ;...

The Discord API has two ways to interact with the bot: The rest API and the gateway. The gateway is an HTTP Websocket which is similar to a stream of data; the connection is always open and is intended to be for a long time. The rest API is a bunch of HTTP "endpoints", or URL's. An example would be https://discord.com/api/v10/users/@me, or https://discord.com/api/v10/guilds/379378609942560770/members. These are plain old HTTP requests, which utilitize HTTP methods (HEAD, GET, POST, DELETE, etc) and HTTP headers (Authorization, Content-Type, Date, etc)

rugged condor
#

OHHH I GET IT

#

LIGHTBULB LIGHTBULB THANK U

meager oriole
#

No problem at all

rugged condor
#

reopening this wound

i got rid of these commands like a day ago, and it’s been running for like 3 hours now. they still won’t go away, when when im updating the commands with [] every time the bot is run

#

this has been my solution for some time while i only register the commands to one guild rather than global:


using (var httpClient = new HttpClient())
            {
                using (var request = new HttpRequestMessage(new HttpMethod("PUT"), "https://discord.com/api/v10/applications/" + ConfigInfo.ApplicationID + "/commands"))
                {
                    request.Headers.TryAddWithoutValidation("Authorization", "Bot " + ConfigInfo.BotToken);

                    request.Content = new StringContent("[]");
                    request.Content.Headers.ContentType = MediaTypeHeaderValue.Parse("application/json");

                    var response = await httpClient.SendAsync(request);
                    Console.ForegroundColor = ConsoleColor.DarkGray;
                    Console.WriteLine(response);
                    Console.ResetColor();
                }
            }
obsidian spindle
#

i answered on your other post

#

please close.

real shale
#

Sorry for bumping this but can anyone demonstrate how to use Insomnia to reset the commands?

aka
➜ Use a tool like Insomnia (https://insomnia.rest/), and PUT [] to api/v10/applications/:app_id/commands*