private Task ComponentCommandExecuted(ComponentCommandInfo arg1, Discord.IInteractionContext arg2, IResult arg3)
        {
            if (!arg3.IsSuccess)
            {
                switch (arg3.Error)
                {
                case InteractionCommandError.UnmetPrecondition:
                    // implement
                    break;

                case InteractionCommandError.UnknownCommand:
                    // implement
                    break;

                case InteractionCommandError.BadArgs:
                    // implement
                    break;

                case InteractionCommandError.Exception:
                    // implement
                    break;

                case InteractionCommandError.Unsuccessful:
                    // implement
                    break;

                default:
                    break;
                }
            }

            return(Task.CompletedTask);
        }
    private Task ComponentCommandExecuted(ComponentCommandInfo commandInfo, IInteractionContext context, IResult result)
    {
        if (!result.IsSuccess)
        {
            switch (result.Error)
            {
            case InteractionCommandError.UnmetPrecondition:
                // implement
                break;

            case InteractionCommandError.UnknownCommand:
                // implement
                break;

            case InteractionCommandError.BadArgs:
                // implement
                break;

            case InteractionCommandError.Exception:
                // implement
                break;

            case InteractionCommandError.Unsuccessful:
                // implement
                break;

            default:
                break;
            }
        }

        return(Task.CompletedTask);
    }
Exemplo n.º 3
0
 /// <summary>
 /// Retrieves the Component Command result and acts accordingly in case of error.
 /// </summary>
 /// <param name="_">The received <see cref="ComponentCommandInfo"/>.</param>
 /// <param name="arg2">The interaction context.</param>
 /// <param name="arg3">The interaction result.</param>
 /// <returns>A task that represents the asynchronous execution operation. The task contains the result of the command execution.</returns>
 public async Task HandleComponentCommandAsync(ComponentCommandInfo _, IInteractionContext arg2, IResult arg3) => await HandleCommandAsync(arg2, arg3);
        /// <summary>
        /// Handle an executed component
        /// Used for buttons, drop downs, etc.
        /// </summary>
        /// <param name="arg1"></param>
        /// <param name="arg2"></param>
        /// <param name="arg3"></param>
        /// <returns></returns>
        private Task ComponentCommandExecuted(ComponentCommandInfo arg1, Discord.IInteractionContext arg2, Discord.Interactions.IResult arg3)
        {
            if (!arg3.IsSuccess)
            {
                // Defer if not already done:
                try
                {
                    arg2.Interaction.DeferAsync(true).GetAwaiter().GetResult();
                }
                catch
                {
                    // ignore
                }

                switch (arg3.Error)
                {
                case InteractionCommandError.UnmetPrecondition:
                    // Check for userperm error:
                    if (arg3.ErrorReason.Contains("UserPerm"))
                    {
                        arg2.Interaction.FollowupAsync("You do not have permission to execute this command.", ephemeral: true);
                        break;
                    }

                    arg2.Interaction.FollowupAsync("Action Failed\n" + arg3.ErrorReason, ephemeral: true);
                    break;

                case InteractionCommandError.UnknownCommand:
                    arg2.Interaction.FollowupAsync("Unknown action. It may have been recently removed or changed.", ephemeral: true);
                    break;

                case InteractionCommandError.BadArgs:
                    arg2.Interaction.FollowupAsync("The provided values are invalid. (BadArgs)", ephemeral: true);
                    break;

                case InteractionCommandError.Exception:
                    //notify owner if desired:
                    if (arg3.ErrorReason.Contains("Invalid Form Body"))
                    {
                        arg2.Interaction.FollowupAsync("Invalid form body. Please check to ensure that all of your parameters are correct.", ephemeral: true);
                        break;
                    }
                    if (notifyOwnerOnError && !string.IsNullOrEmpty(_config["OwnerID"]))
                    {
                        string error = Format.Bold("Error:") + "\n" + Format.Code(arg3.ErrorReason) + "\n\n" + Format.Bold("Command:") + "\n" + Format.BlockQuote(arg1.Name + " " + DiscordTools.SlashParamToString(arg2));
                        if (error.Length > 2000)
                        {
                            error = error.Substring(0, 2000);
                        }
                        UserExtensions.SendMessageAsync(_client.GetUser(ulong.Parse(_config["OwnerID"])), error);
                    }
                    arg2.Interaction.FollowupAsync("Sorry, Something went wrong...", ephemeral: true);
                    break;

                case InteractionCommandError.Unsuccessful:
                    //notify owner if desired:
                    if (notifyOwnerOnError && !string.IsNullOrEmpty(_config["OwnerID"]))
                    {
                        string error = Format.Bold("Error:") + "\n" + Format.Code(arg3.ErrorReason) + "\n\n" + Format.Bold("Command:") + "\n" + Format.BlockQuote(arg1.Name + " " + DiscordTools.SlashParamToString(arg2));
                        if (error.Length > 2000)
                        {
                            error = error.Substring(0, 2000);
                        }
                        UserExtensions.SendMessageAsync(_client.GetUser(ulong.Parse(_config["OwnerID"])), error);
                    }
                    arg2.Interaction.FollowupAsync("Sorry, Something went wrong...", ephemeral: true);
                    break;

                default:
                    //notify owner if desired:
                    if (notifyOwnerOnError && !string.IsNullOrEmpty(_config["OwnerID"]))
                    {
                        string error = Format.Bold("Error:") + "\n" + Format.Code(arg3.ErrorReason) + "\n\n" + Format.Bold("Command:") + "\n" + Format.BlockQuote(arg1.Name + " " + DiscordTools.SlashParamToString(arg2));
                        if (error.Length > 2000)
                        {
                            error = error.Substring(0, 2000);
                        }
                        UserExtensions.SendMessageAsync(_client.GetUser(ulong.Parse(_config["OwnerID"])), error);
                    }
                    arg2.Interaction.FollowupAsync("Sorry, Something went wrong...");
                    break;
                }
            }

            return(Task.CompletedTask);
        }