/// <summary>
        /// Not currently used
        /// </summary>
        /// <param name="arg1"></param>
        /// <param name="arg2"></param>
        /// <param name="arg3"></param>
        /// <returns></returns>
        private Task ContextCommandExecuted(ContextCommandInfo arg1, Discord.IInteractionContext arg2, Discord.Interactions.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);
        }
示例#2
0
        async Task SlashCommandExecuted(SlashCommandInfo arg1, Discord.IInteractionContext arg2, Discord.Interactions.IResult arg3)
        {
            if (!arg3.IsSuccess)
            {
                switch (arg3.Error)
                {
                case InteractionCommandError.UnmetPrecondition:
                    await arg2.Interaction.RespondAsync($"Unmet Precondition: {arg3.ErrorReason}", ephemeral : true);

                    break;

                case InteractionCommandError.UnknownCommand:
                    await arg2.Interaction.RespondAsync("Unknown command", ephemeral : true);

                    break;

                case InteractionCommandError.BadArgs:
                    await arg2.Interaction.RespondAsync("Invalid number or arguments", ephemeral : true);

                    break;

                case InteractionCommandError.Exception:
                    Console.WriteLine("Command Error:");
                    Console.WriteLine(arg3.ErrorReason);
                    await arg2.Interaction.RespondAsync($"Command exception: {arg3.ErrorReason}. If this message persists, please let us know in the support server (https://discord.gg/xyzMyJH) !", ephemeral : true);

                    break;

                case InteractionCommandError.Unsuccessful:
                    await arg2.Interaction.RespondAsync("Command could not be executed", ephemeral : true);

                    break;

                default:
                    break;
                }
            }
        }
        /// <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);
        }