Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package com.zenyte;
- import java.io.OutputStream;
- import java.net.HttpURLConnection;
- import java.net.URL;
- import java.time.LocalDateTime;
- import java.time.format.DateTimeFormatter;
- /**
- @author Jack @ The CErver | Feb 5th, 2024
- This file should be in com.zenyte on a Zenyte code base.
- */
- public class DiscordLog {
- public static final String ERROR_WEBHOOK = "YOUR URL GOES HERE";
- public static void error(String message) {
- try {
- URL url = new URL(ERROR_WEBHOOK);
- LocalDateTime timestamp1 = LocalDateTime.now();
- DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss");
- String timestamp = timestamp1.format(formatter);
- HttpURLConnection connection = (HttpURLConnection) url.openConnection();
- connection.setRequestMethod("POST");
- connection.setRequestProperty("Content-Type", "application/json");
- connection.setDoOutput(true);
- String jsonPayload = "{\"content\":\"```["+ timestamp + "] The CErver Logs: " + message + "```\"}";
- try (OutputStream os = connection.getOutputStream()) {
- byte[] input = jsonPayload.getBytes("utf-8");
- os.write(input, 0, input.length);
- }
- int responseCode = connection.getResponseCode();
- if (responseCode == 204) {
- System.out.println("Message sent to Discord successfully.");
- } else {
- System.out.println("Failed to send message to Discord. HTTP Response Code: " + responseCode);
- System.out.println("Failed to send to Discord. HTTP Response Code: " + responseCode);
- }
- }
- catch (Exception e) {
- e.printStackTrace();
- }
- }
- // 1: Add your custom channel logs here. Copy the public from error to get started.
- // 2: Underneath public static final String ERROR_WEBHOOK, copy the line and rename ERROR_WEBHOOK to your new hook name.
- // 3: Create your void here. Format: public static void NAME(String message) {
- // 4: Fill the contents with the code from error
- // 5: Change the URL line to the NAME_WEBHOOK you defined in step 2
- // 6: Call your function using DiscordLog.name("Log string");
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement