Medusa Posted July 23, 2019 Share Posted July 23, 2019 (edited) I'll be teaching you how to send messages to your discord channel from your botting script. This can be useful for a number of things; Level messages, PvE drops, Out of food and a lot of other things. I'll be using this json library, but you can re-write the code snippet so you won't need the library (If you know how). If you want to know how you can "import" the library to your compiled script, just watch this spoiler. Spoiler Official Discord webhook API is here Let's get started The following code is the function to send a discord message. You want to add this anywhere in your code. It has come to my attention that I'm a retard, and that I initialize variables inside methods. Please fix this yourself :)) Spoiler 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", "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/66.0.3359.139 Safari/537.36"); //Create the needed parameters as a json object. JSONObject json = new JSONObject(); json.put("content", content); json.put("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.toString()); 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(); } The response code for invalid webhook is: { "code": 50027, "message": "Invalid Webhook Token" } Empty message response code: { "code": 50006, "message": "Cannot send an empty message" } Once you've got the function in your project you're ready to use it. discordMessage("Your webhook url", "the message you want to send", "Any username really. You can use the name of the account logged in if you want"); If you don't know how to create a discord webhook, look at this spoiler. Spoiler First your want to find the channel you want the messages to appear in. You need to have access to webhooks in order to do this. Then you want to right-click the text-channel you want the messages to appear in, and click "Edit Channel". Now you should be in the channel settings, and you should be able to see a button called "Webhooks". Click that Then you get to the webhook settings, where you need to create a new webhook (Or edit an already existing one) After clicking create (or edit), a UI should open. Here you can see your webhook url. Edited October 3, 2019 by Medusa 10 1 1 Quote Link to comment Share on other sites More sharing options...
Night Posted July 23, 2019 Share Posted July 23, 2019 Nice little tutorial, if you want even more customization I'd check out the "Hookscord" library on github. Quote Link to comment Share on other sites More sharing options...
Ragboys is back Posted July 23, 2019 Share Posted July 23, 2019 Thank you for this! Amazing, will definetely be using it for some scripts in the future =] Quote Link to comment Share on other sites More sharing options...
Lost Panda Posted July 23, 2019 Share Posted July 23, 2019 Good helpful guide fren, gj. Quote Link to comment Share on other sites More sharing options...
Czar Posted July 23, 2019 Share Posted July 23, 2019 Interesting idea, thanks for the guide really appreciate it ^^ Quote Link to comment Share on other sites More sharing options...
Stuggles Posted July 23, 2019 Share Posted July 23, 2019 Nice! Quote Link to comment Share on other sites More sharing options...
DeadPk3r Posted July 24, 2019 Share Posted July 24, 2019 Interesting never really thought about having a script use discord nice tutorial. Quote Link to comment Share on other sites More sharing options...
Gpstacker57 Posted November 22, 2019 Share Posted November 22, 2019 tips on how to fix the code to get it working? would love to be able to use this but I'm getting a: java.lang.NoClassDefFoundError: org/json/JSONObject Much love Quote Link to comment Share on other sites More sharing options...
Medusa Posted November 22, 2019 Author Share Posted November 22, 2019 (edited) 5 hours ago, Gpstacker57 said: tips on how to fix the code to get it working? would love to be able to use this but I'm getting a: java.lang.NoClassDefFoundError: org/json/JSONObject Much love Made a gif showing how to get that working. Edited November 22, 2019 by Medusa Quote Link to comment Share on other sites More sharing options...
JScout Posted June 2, 2020 Share Posted June 2, 2020 Medusa you Always be my #1 Any example ideas this can be used for? Quote Link to comment Share on other sites More sharing options...
Medusa Posted June 2, 2020 Author Share Posted June 2, 2020 5 hours ago, Fishbot said: Medusa you Always be my #1 Any example ideas this can be used for? Can be used for a lot of things tbh. Level gained notifications, Scouts, Out of supplies notifications etc. Quote Link to comment Share on other sites More sharing options...
Bnywarrior Posted June 2, 2020 Share Posted June 2, 2020 (edited) Do you reckon you can extend this bot to respond to any1 taking to you? ie; it sends you discord msg and you can reply. For example: bot: “name”:”wc lvl?” you: !reply “60, wbu?” Actually, using a discord bot to configure script behavior would be pretty neat, !stop !break 20 minutes !status This is some cool stuff, Medusa Edited June 2, 2020 by Bnywarrior Quote Link to comment Share on other sites More sharing options...
Medusa Posted June 2, 2020 Author Share Posted June 2, 2020 1 hour ago, Bnywarrior said: Do you reckon you can extend this bot to respond to any1 taking to you? ie; it sends you discord msg and you can reply. For example: bot: “name”:”wc lvl?” you: !reply “60, wbu?” Actually, using a discord bot to configure script behavior would be pretty neat, !stop !break 20 minutes !status This is some cool stuff, Medusa Don't think there is a way to implement something like that without writing an actual discord bot. Quote Link to comment Share on other sites More sharing options...
JScout Posted June 2, 2020 Share Posted June 2, 2020 4 hours ago, Medusa said: Can be used for a lot of things tbh. Level gained notifications, Scouts, Out of supplies notifications etc. Is it possible/you know how to send things In reverse? Like sending commands in discord on that webhook !stop !start !attackMedusa Like that kind of stuff? ^^ Quote Link to comment Share on other sites More sharing options...
Jueix Posted August 4, 2020 Share Posted August 4, 2020 Thank you, Now I can get progress updates on my custom scripts more easily :). facebook get photo by id Quote Link to comment Share on other sites More sharing options...