#Throwing Exception

1 messages · Page 1 of 1 (latest)

frank tapir
#

I throw exception and I got error about it,

#

so I check hierarchy if statement is true then I throw exception

#

I check here, everything is fine so far,

#

I got error here I guess

#

my error saying:

User
Event handler exception for event SLASHCOMMAND_ERRORED thrown from System.Threading.Tasks.Task SlashCommandError(DSharpPlus.SlashCommands.SlashCommandsExtension, DSharpPlus.SlashCommands.EventArgs.SlashCommandErrorEventArgs) (defined in FIrstDiscordBotC_.Program)
DSharpPlus.Exceptions.BadRequestException: Bad request: 400
at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
at System.Runtime.CompilerServices.TaskAwaiter.ValidateEnd(Task task)
at DSharpPlus.Net.DiscordApiClient.<CreateInteractionResponseAsync>d__174.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
at System.Runtime.CompilerServices.TaskAwaiter.GetResult()
at FIrstDiscordBotC_.Configurations.GlobalExceptionHandler.<HierarchyError>d__5.MoveNext() in C:\Users\User\Desktop\DiscordBots\DiscordBotDSharpPlus\Configurations\GlobalExceptionHandler.cs:line 112
--- End of stack trace from previous location where exception was thrown ---
at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
at System.Runtime.CompilerServices.TaskAwaiter.GetResult()
at FIrstDiscordBotC_.Configurations.GlobalExceptionHandler.<HandleErrors>d__1.MoveNext() in C:\Users\User\Desktop\DiscordBots\DiscordBotDSharpPlus\Configurations\GlobalExceptionHandler.cs:line 63
--- End of stack trace from previous location where exception was thrown ---
at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
at System.Runtime.CompilerServices.TaskAwaiter.GetResult()
at FIrstDiscordBotC_.Program.<SlashCommandError>d__3.MoveNext() in C:\Users\User\Desktop\DiscordBots\DiscordBotDSharpPlus\Program.cs:line 80
--- End of stack trace from previous location where exception was thrown ---
at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
at DSharpPlus.AsyncEvents.AsyncEvent`2.<>c__DisplayClass7_0.<<InvokeAsync>b__0>d.MoveNext()

unborn mulch
#

deferring creates a response

#

you can't create two responses

frank tapir
# unborn mulch you can't create two responses

Sorry, but in HandleErrors method I also have PermissionError which when user deosnt have permission to do smth, this exception happened. And it works fine. So whats difference between this Creating Response

#

They both comes from Ban method

unborn mulch
#

because your permission check happens before the DeferAsync call

frank tapir
unborn mulch
#

i recommend either making the hierarchy a pre-execution check too or handling it without throwing an exception