Jueix Posted February 21, 2023 Share Posted February 21, 2023 (edited) Started a new bot script and tried implementing this again ( tried to even re-write my firemaker script by copying project files and re-writing the code apart from the discord part ) if I use normal firemaker jar i didnt edit it sends the messages but if I don't and create a new project it gives me this error Error in bot executor or from Error class (and not Exception)! java.lang.NoClassDefFoundError: org/json/JSONObject at core.Main.discordMessage(Main.java:30) at core.Main.onLoop(Main.java:58) at org.osbot.rs07.event.ScriptExecutor$InternalExecutor.run(jf:86) at java.lang.Thread.run(Unknown Source) Caused by: java.lang.ClassNotFoundException: org.json.JSONObject at java.net.URLClassLoader.findClass(Unknown Source) at java.lang.ClassLoader.loadClass(Unknown Source) at java.lang.ClassLoader.loadClass(Unknown Source) ... 4 more You use to have a gif that would show you how to fix this error but it doesn't work for me anymore. Sorry for posting on such a old thread but wanted to implement it back into some of my scripts again. Edited February 21, 2023 by Jueix Quote Link to comment Share on other sites More sharing options...
Jueix Posted March 15, 2023 Share Posted March 15, 2023 On 2/21/2023 at 2:28 PM, Jueix said: Started a new bot script and tried implementing this again ( tried to even re-write my firemaker script by copying project files and re-writing the code apart from the discord part ) if I use normal firemaker jar i didnt edit it sends the messages but if I don't and create a new project it gives me this error Error in bot executor or from Error class (and not Exception)! java.lang.NoClassDefFoundError: org/json/JSONObject at core.Main.discordMessage(Main.java:30) at core.Main.onLoop(Main.java:58) at org.osbot.rs07.event.ScriptExecutor$InternalExecutor.run(jf:86) at java.lang.Thread.run(Unknown Source) Caused by: java.lang.ClassNotFoundException: org.json.JSONObject at java.net.URLClassLoader.findClass(Unknown Source) at java.lang.ClassLoader.loadClass(Unknown Source) at java.lang.ClassLoader.loadClass(Unknown Source) ... 4 more You use to have a gif that would show you how to fix this error but it doesn't work for me anymore. Sorry for posting on such a old thread but wanted to implement it back into some of my scripts again. If anyone is having the same thing here's an updated script that works with my newest script that doesn't use the JSON libary. private static final String USER_AGENT = "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/66.0.3359.139 Safari/537.36"; /*send discord messages */ public static void discordMessage(String url, String content, String username) throws IOException { URL webhookUrl = new URL(url); HttpURLConnection con = (HttpURLConnection)webhookUrl.openConnection(); //Set the request headers. con.setDoOutput(true); con.setRequestMethod("POST"); con.addRequestProperty("Content-Type", "application/json"); con.addRequestProperty("User-Agent", USER_AGENT); //Create the JSON string to send in the request body. String json = "{ \"content\": \"" + content + "\", \"username\": \"" + username + "\" }"; //Add to the body of the request (The content needed gets added to the request) BufferedWriter writer = new BufferedWriter(new OutputStreamWriter(con.getOutputStream())); writer.write(json); writer.close(); //Create a new StringBuilder to store the request response (Not needed if you don't check if the request was successful StringBuilder sb = new StringBuilder(); //Actually send the request to the discord webhook Scanner scanner = new Scanner(con.getInputStream()); while(scanner.hasNextLine()) { sb.append(scanner.nextLine()); } scanner.close(); } Quote Link to comment Share on other sites More sharing options...
Chris Posted March 15, 2023 Share Posted March 15, 2023 5 hours ago, Jueix said: If anyone is having the same thing here's an updated script that works with my newest script that doesn't use the JSON libary. private static final String USER_AGENT = "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/66.0.3359.139 Safari/537.36"; /*send discord messages */ public static void discordMessage(String url, String content, String username) throws IOException { URL webhookUrl = new URL(url); HttpURLConnection con = (HttpURLConnection)webhookUrl.openConnection(); //Set the request headers. con.setDoOutput(true); con.setRequestMethod("POST"); con.addRequestProperty("Content-Type", "application/json"); con.addRequestProperty("User-Agent", USER_AGENT); //Create the JSON string to send in the request body. String json = "{ \"content\": \"" + content + "\", \"username\": \"" + username + "\" }"; //Add to the body of the request (The content needed gets added to the request) BufferedWriter writer = new BufferedWriter(new OutputStreamWriter(con.getOutputStream())); writer.write(json); writer.close(); //Create a new StringBuilder to store the request response (Not needed if you don't check if the request was successful StringBuilder sb = new StringBuilder(); //Actually send the request to the discord webhook Scanner scanner = new Scanner(con.getInputStream()); while(scanner.hasNextLine()) { sb.append(scanner.nextLine()); } scanner.close(); } if u every wanna work with json, osbot has Gson lib packaged with it Quote Link to comment Share on other sites More sharing options...