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

Creating commands returns error 20001

Open HAHOOS opened this issue 3 years ago • 4 comments

Hello, I was recently making a ticket bot and I wanted to make commands, I wrote the code, but it was returning error 20001 and I can't fix it, please help! image Code:

public async Task Create()
        {
            List<ApplicationCommandProperties> applicationCommandProperties = new List<ApplicationCommandProperties>();
            var close = new SlashCommandBuilder()
                .WithName("close")
                .WithDescription("Close current ticket you are in")
                .WithDefaultMemberPermissions(GuildPermission.ManageMessages)
                .WithDMPermission(false)
                .WithDefaultPermission(true)
                .AddOption(new SlashCommandOptionBuilder()
                  .WithName("reason")
                  .WithDescription("Reason for closing ticket")
                  .WithType(ApplicationCommandOptionType.String)
                  .WithRequired(false)
                );
            var perfomance = new SlashCommandBuilder()
                .WithName("perfomance")
                .WithDescription("Check perfomance of bot such as Ping, RAM Usage and more!")
                .WithDefaultPermission(true)
                .WithDMPermission(true);
            applicationCommandProperties.Add(close.Build());
            applicationCommandProperties.Add(perfomance.Build());
            try
            {
                // Now that we have our builder, we can call the CreateApplicationCommandAsync method to make our slash command.
                await Program.client.BulkOverwriteGlobalApplicationCommandsAsync(applicationCommandProperties.ToArray());
            }
            catch (HttpException exception)
            {
                // If our command was invalid, we should catch an ApplicationCommandException. This exception contains the path of the error as well as the error message. You can serialize the Error field in the exception to get a visual of where your error is.
                Console.WriteLine(exception.Message);
            }
        }

HAHOOS avatar Jul 04 '22 19:07 HAHOOS

I suspect you're executing this call before the REST client is fully ready. Please move this code to the DiscordSocketClient.Ready event and see if that works.

csmir avatar Aug 01 '22 16:08 csmir

Could you follow up? Has the issue been resolved?

csmir avatar Aug 21 '22 12:08 csmir

I suspect you're executing this call before the REST client is fully ready. Please move this code to the DiscordSocketClient.Ready event and see if that works.

Alright, I will try

HAHOOS avatar Aug 23 '22 12:08 HAHOOS

Any updates?

csmir avatar Aug 29 '22 09:08 csmir

Closing by lack of followup.

csmir avatar Nov 08 '22 11:11 csmir