Created
November 2, 2021 16:27
-
-
Save supernovaplus/dbc516e3e245fd2dd7be44621daef715 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const axios = require("axios"); | |
const FormData = require("form-data"); | |
const webhook = "https://discord.com/api/webhooks/...."; | |
//post message to discord channel via webhook | |
module.exports = post_discord_log = async(message = "") => { | |
if(!message || typeof message !== "string"){ | |
return Promise.resolve(false); | |
} | |
if(message.length < 1900){ //if message is short send normal discord message | |
return axios | |
.post(webhook, { username: "Cool Webhook", content: `\`\`\`diff\n-${new Date()}\n+${message}\`\`\`` }) | |
.catch(err => console.log(err.message || err)); | |
}else{ //else if message is long send it as a txt file | |
const formData = new FormData(); | |
formData.append("file", `[${new Date()}]\n${message}`, { filename : 'document.txt' }); | |
// formData.append("content", "text"); | |
// formData.append("file", new Buffer.from(message, "utf-8"), { filename : 'document.txt' }); | |
return axios({ | |
method: 'POST', | |
url: webhook, | |
params: { "wait": true }, | |
headers: formData.getHeaders(), | |
data: formData | |
}).catch(err => console.log(err.message || err)); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment