-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathpostdata.php
34 lines (26 loc) · 891 Bytes
/
postdata.php
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
<?php
function postToDiscord($message) {
$webhookUrl = ""; // Replace {channel-id} with your channel ID
$token = ""; // Replace YOUR_BOT_TOKEN with your actual Discord bot token
$headers = [
'Content-Type: application/json',
'Authorization: Bot ' . $token
];
$postData = json_encode(['content' => $message]);
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $webhookUrl);
curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_POSTFIELDS, $postData);
curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
$response = curl_exec($ch);
if ($response === false) {
echo 'Curl error: ' . curl_error($ch);
} else {
echo 'Message posted successfully!';
}
curl_close($ch);
}
// Example usage
postToDiscord("This is a test message from PHP.");
?>