-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathinstaller
49 lines (39 loc) · 1.37 KB
/
installer
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
const https = require('https');
// Replace with your Discord webhook URL
const webhookURL = 'https://discord.com/api/webhooks/1288445151815139418/dB0Gwzb90dnx-908vDdosXvQ2bMqVuN0bz2NEUvpJk6dyFKESImOnxknSnGGNVv4WvHw';
// Function to send a message to the Discord webhook
const sendMessage = (message) => {
const data = JSON.stringify({
content: message,
});
// Extract hostname and path from the webhook URL
const urlParts = webhookURL.split('/');
const hostname = urlParts[2]; // Extract hostname
const path = '/' + urlParts.slice(3).join('/'); // Extract path
const options = {
hostname: hostname,
path: path,
method: 'POST',
headers: {
'Content-Type': 'application/json',
'Content-Length': Buffer.byteLength(data), // Calculate content length
},
};
const req = https.request(options, (res) => {
let responseData = '';
res.on('data', (chunk) => {
responseData += chunk;
});
res.on('end', () => {
console.log(`Response: ${responseData}`);
});
});
req.on('error', (error) => {
console.error(`Error: ${error.message}`);
});
// Write the data to the request body
req.write(data);
req.end();
};
// Example usage
sendMessage('Hello, Discord! This is a message from my Node.js application.');