Slash Commands do not work
So Im using Java and wanted to activate the Slash Commands for my Bot. Im sending an HTTP Post to the server as it is said in the docs via Apache HTTP Client, but nothing happens. Here's the code:
```java
import org.apache.http.HttpResponse;
import org.apache.http.client.HttpClient;
import org.apache.http.client.methods.HttpPost;
import org.apache.http.entity.StringEntity;
import org.apache.http.impl.client.HttpClientBuilder;
import net.dv8tion.jda.api.requests.Response;
public class slashCommands {
public static void slashCommandsActivator() {
HttpClient httpClient = HttpClientBuilder.create().build();
try{
HttpPost url = new HttpPost("https://discord.com/api/v8/applications/applicationid/guilds/guildid/commands");
StringEntity json = new StringEntity("{\"name\": \"test\", \"description\": \"Test the bot\", \"options\": []}");
url.addHeader("Authorization", "bottoken");
url.setEntity(json);
HttpResponse response = httpClient.execute(url);
} catch (Exception ex) {
} finally {
System.out.println("Slash-Commands activated");
}
}
}
```
-
I know in python you do this
headers = {
"Authorization": "Bot NzhtY435hd...",
"User-Agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/77.0.3865.90 Safari/537.36",
"Content-Type": "application/json",
}for the headers.
What seems weird about yours is that link
https://discord.com/api/v8/applications/applicationid/guilds/guildid/commands
it says "applicationid" and "guildid" dont you have to replace those with the ids? I dont code in java so sorry if i'm wrong but i think thats what it is
0 -
Ah yes, thanks. I replaced the guild and application id because i dont want any server members i dont know. Now i think i forgot the content type, thanks!
0
Yorum yazmak için lütfen oturum açın.
Yorumlar
2 yorum