ScriptWizard 5 Posted June 1, 2024 The easiest and only webhook class youll EVER need in your life! package org.dreambot.utilities; import java.io.IOException; import java.io.OutputStream; import java.net.HttpURLConnection; import java.net.URL; import java.nio.charset.StandardCharsets; import java.util.Random; import static org.dreambot.api.utilities.Logger.log; public class Webhooks { private static final String WEBHOOK_URL = "YOUR WEBHOOK HERE, CHANGE THIS"; public static void sendToWebhook(String title, String playerName, String amount, String totalCoin, String imageUrl) { if (playerName == null || playerName.isEmpty()) { log("PlayerName is invalid: " + playerName); return; } if (amount == null || amount.isEmpty()) { log("Amount is invalid: " + amount); return; } if (totalCoin == null || totalCoin.isEmpty()) { log("TotalCoin is invalid: " + totalCoin); return; } if (imageUrl == null || imageUrl.isEmpty()) { log("Image URL is invalid: " + imageUrl); return; } Random random = new Random(); int color = random.nextInt(0xFFFFFF + 1); String jsonPayload = String.format("{\n" + " \"content\": \"_ _\",\n" + " \"embeds\": [\n" + " {\n" + " \"title\": \"%s\",\n" + " \"description\": \"\",\n" + " \"fields\": [\n" + " {\n" + " \"name\": \"Player Name\",\n" + " \"value\": \"%s\"\n" + " },\n" + " {\n" + " \"name\": \"Amount\",\n" + " \"value\": \"%s\"\n" + " },\n" + " {\n" + " \"name\": \"Total Coin\",\n" + " \"value\": \"%s\"\n" + " }\n" + " ],\n" + " \"color\": %d,\n" + " \"image\": {\n" + " \"url\": \"%s\"\n" + " }\n" + " }\n" + " ],\n" + " \"attachments\": []\n" + "}", title, playerName, amount, totalCoin, color, imageUrl); try { int code = getCode(jsonPayload); log("Response code: " + code); } catch (Exception e) { log("Error while sending webhook: " + e.getMessage()); } } private static int getCode(String jsonPayload) throws IOException { URL url = new URL(WEBHOOK_URL); HttpURLConnection connection = (HttpURLConnection) url.openConnection(); connection.setRequestMethod("POST"); connection.setRequestProperty("User-Agent", "Java-DiscordWebhook-Bot"); connection.setRequestProperty("Content-Type", "application/json; utf-8"); connection.setRequestProperty("Accept", "application/json"); connection.setDoOutput(true); try (OutputStream os = connection.getOutputStream()) { byte[] input = jsonPayload.getBytes(StandardCharsets.UTF_8); os.write(input, 0, input.length); } return connection.getResponseCode(); } } With this class, you can utilize the method for webhooking in an extremely simple way Webhook example: sendToWebhook("TITLE GOES HERE", "", "", "", ""); To simplify the webhook image you can make a global variable for this. I personally use TreeBranchFramework so I put the image in my API. https://discordjs.guide/popular-topics/embeds.html#using-the-embed-constructor This is a useful documentation on discords embed system. This is json, NOT embedbuilder. NO you cannot mention inside the embed. You must modify this to do so(I wont do it for you). Just change the names annd values to correspond with your project. Fields name will be bold, value will not be. Hope this helps anyone needing webhooks in their scripts! Here is an example image of what my mule looks like with this. This is a modified version of something @DumbRat691 sent me. MaximusPrimo 1
ScriptWizard 5 Author Posted June 1, 2024 1 minute ago, DumbRat691 said: pog, np Ty I wasnt gonna share the other classes I utilize for the other shit but this ones worthy of sharing.
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now