Closed Dei-Ma closed 3 years ago
Hello! You need to at least acknowledge the interaction using acknowledge()
if you're not directly responding to it.
Hi, this leads me to my next Problem:
the acknowledge fails with this error.
Caused by: de.cerus.jdasc.http.DiscordApiException: Expected one of [200, 204] but got 400
Huh, that's strange. Do the commands register without problems? Does your bot have the right permissions?
Yes they do, but deleting a command does not work neither.
i guess that all permissions are ok.
Maybe it has to do with this
Using your favorite security library, you must validate the request each time you receive an interaction. If the signature fails validation, respond with a 401 error code. Here's a couple code examples:
Using your favorite security library, you must validate the request each time you receive an interaction. If the signature fails validation, respond with a 401 error code. Here's a couple code examples:
That's only if you use webhooks to receive interactions. This library hooks into the Discord bot so no webhook is needed.
Take a look at this reply from another issue, did you check this box when you generated an invite link for your bot?
My invitation Link ends like this: &permissions=3959946304&scope=bot%20applications.commands
interaction.acknowledge()
will return you a CompletableFuture, you could check using whenComplete()
if the throwable is an instance of DiscordApiException
, and if it is one you can cast the throwable and print out the response body. This would help to diagnose the issue.
Do you mean this?:
Response{protocol=h2, code=400, message=, url=https://discord.com/api/v8/interactions/..........
Yes, but the response should have a method that returns you only the body that was sent. That's all we need
response.body.toString() -> okhttp3.internal.http.RealResponseBody@37df9063
sorry I am very new to this
I kept trying....
may this be the response body?: {"redirect":false,"successful":false}
response.body().string()
should work
{"code": 50035, "errors": {"type": {"_errors": [{"code": "BASE_TYPE_CHOICES", "message": "Value must be one of (1, 4, 5, 6, 7)."}]}}, "message": "Invalid Form Body"}
Hm, looks like you chose an invalid option for one of your sub commands (I think). Would you mind sharing your code where you register the commands?
public static void initCommands(JDA jda) throws ExecutionException, InterruptedException {
JDASlashCommands.initialize(jda, Config.BOT_TOKEN, Config.APPLICATION_ID);
List<ApplicationCommandOptionChoice> choices = new ArrayList<>();
choices.add( new ApplicationCommandOptionChoice("Liga 1", "1"));
choices.add( new ApplicationCommandOptionChoice("Liga 2", "2"));
JDASlashCommands.submitGuildCommand(new CommandBuilder()
.name("standings") // Set command name to '/test-command'
.desc("Shows the standings of a league")
.option(new ApplicationCommandOption(ApplicationCommandOptionType.STRING,
"league",
"Specify your league",
true,
choices,
null))
.option(new ApplicationCommandOption(ApplicationCommandOptionType.INTEGER,
"group",
"Specify your group league",
false))
.build(), channelId ,new ApplicationCommandListener() {
@Override
public void onInteraction(final Interaction interaction) {
try {
interaction.acknowledge(true).get();
} catch (InterruptedException e) {
e.printStackTrace();
} catch (ExecutionException e) {
e.printStackTrace();
}
try {
switch (interaction.getCommandName().toLowerCase()) {
case "standings": cmd.standings(interaction, false);break;
default: cmd.unknownCommand(interaction);break;
}
} catch (Exception e) {
interaction.getChannel().sendMessage(e.getMessage()).queue();
return;
}
String result = interaction.getCommandName() + " " + interaction.getOption("league").getValue();
System.out.println(result);
}});
}
Looks like you can't use the STRING option directly on commands. It looks like you will have to register a sub command to use that option.
I changed it. But first of all, it does not look like that what I want anymore, and second, it has the same Problem:
{"code": 50035, "errors": {"type": {"_errors": [{"code": "BASE_TYPE_CHOICES", "message": "Value must be one of (1, 4, 5, 6, 7)."}]}}, "message": "Invalid Form Body"}
I tried to delete my first Test Commands.
List<ApplicationCommand> existingCommands = JDASlashCommands.getGlobalCommands().get(); for(ApplicationCommand currentCommand : existingCommands){ JDASlashCommands.deleteGlobalCommand(currentCommand.getId()); }
This is not working to. Maybe it has a same kind of reason.
In this case I get
Caused by: de.cerus.jdasc.http.DiscordApiException: Expected one of [204] but got 401 {"message": "401: Unauthorized", "code": 0}
In your code I find this:
public CompletableFuture<Response> deleteGlobalCommand(final long commandId) { return this.execute(new Request.Builder() .url(String.format("https://discord.com/api/v8/applications/%s/commands/%d", this.applicationId, commandId)) .delete() .build(), 204); }
public CompletableFuture<Response> deleteGuildCommand(final long commandId, final long guildId) { return this.execute(new Request.Builder() .url(String.format("https://discord.com/api/v8/applications/%s/guilds/%d/commands/%d", this.applicationId, guildId, commandId)) .delete() .addHeader("Authorization", "Bot " + this.botToken) .build(), 204); }
is the Header with Authorization not needed in case of deleting a GlobalCommand?
I changed it. But first of all, it does not look like that what I want anymore, and second, it has the same Problem:
{"code": 50035, "errors": {"type": {"_errors": [{"code": "BASE_TYPE_CHOICES", "message": "Value must be one of (1, 4, 5, 6, 7)."}]}}, "message": "Invalid Form Body"}
Back to this Problem.
if I Change from interaction.acknowledge(true) to interaction.acknowledge(false)
I get this Response
{"message": "Unknown interaction", "code": 10062}
and this error Cannot invoke "de.cerus.jdasc.interaction.response.InteractionResponseOption.getValue()" because the return value of "de.cerus.jdasc.interaction.Interaction.getOption(String)" is null
Caused by: de.cerus.jdasc.http.DiscordApiException: Expected one of [200, 204] but got 404
I found out that the InteractionResponseType ACKNOWLEDGE has the Value 2, so this response makes sense. 2 Is not valid.
{"code": 50035, "errors": {"type": {"_errors": [{"code": "BASE_TYPE_CHOICES", "message": "Value must be one of (1, 4, 5, 6, 7)."}]}}, "message": "Invalid Form Body"}
https://discord.com/developers/docs/interactions/slash-commands#interaction-response
Ok After I added okhttp to my Gradle some of the Problems are fixed. implementation group: 'com.squareup.okhttp3', name: 'okhttp', version: '4.9.1'
But others are still there.
.addHeader("Authorization", "Bot " + this.botToken
On the other Hand. This ist working
Works but leads in to an endless loading state for the interaction
What exactly do you mean by that?
Looks like Discord completely changed the slash commands api, great. I'll have to make a few changes to get everything working again.
The bot ist still thinking......
I'll wait for #11 to get ready and then I'll update the library. Danke Discord.
Alright, updating the lib was less work than I expected. Everything should work as expected now. Updates are in develop
I tried to delete my first Test Commands.
List<ApplicationCommand> existingCommands = JDASlashCommands.getGlobalCommands().get(); for(ApplicationCommand currentCommand : existingCommands){ JDASlashCommands.deleteGlobalCommand(currentCommand.getId()); }
This is not working to. Maybe it has a same kind of reason.
In this case I get
Caused by: de.cerus.jdasc.http.DiscordApiException: Expected one of [204] but got 401 {"message": "401: Unauthorized", "code": 0}
In your code I find this:
public CompletableFuture<Response> deleteGlobalCommand(final long commandId) { return this.execute(new Request.Builder() .url(String.format("https://discord.com/api/v8/applications/%s/commands/%d", this.applicationId, commandId)) .delete() .build(), 204); }
public CompletableFuture<Response> deleteGuildCommand(final long commandId, final long guildId) { return this.execute(new Request.Builder() .url(String.format("https://discord.com/api/v8/applications/%s/guilds/%d/commands/%d", this.applicationId, guildId, commandId)) .delete() .addHeader("Authorization", "Bot " + this.botToken) .build(), 204); }
is the Header with Authorization not needed in case of deleting a GlobalCommand?
Didn't you fix this, or am I wrong?
It's fixed in the dev branch
ok I found it. Thank you! I am looking forward to the release until then my workarounds work ;)
Alright, great! I'm going to close this issue then. Feel free to open another one if you have any further questions.
P.S. I send you a friend request on discord
Hi,
I managed ti get my first Slash Command and it works pretty good.
But I get en error in Discord that says "Interaction failed".
Maybe it has something to do with this
Interaction tokens are valid for 15 minutes and can be used to send followup messages but you must send an initial response within 3 seconds of receiving the event. If the 3 second deadline is exceeded, the token will be invalidated.
But I could not find out how to make an initial repond.
Can someone help me?
regards