対象チャンネルの歯車(チャンネルの編集)をクリック
![discordチャンネルの編集](https://halfpower.work/wp-content/uploads/2022/09/1-2.png)
「連携サービス」 -> 「ウェブフックを作成」をクリック
![discordウェブフックを作成](https://halfpower.work/wp-content/uploads/2022/09/2-1024x410.png)
「ウェブフックURLをコピー」をクリック
![](https://halfpower.work/wp-content/uploads/2022/09/4-1.png)
PHPのソースに貼り付ける
$contents = '投稿したい内容';
$message = array(
'username' => 'Botです', // 投稿者名
'content' => $contents
);
// ↓コピーしたウェブフックURLを貼り付け
$webhook_url = 'https://discord.com/api/webhooks/xxxxxxxx/xxxxxxxxxxxxxxxxxxxxxxxxxx';
$options = array(
'http' => array(
'method' => 'POST',
'header' => 'Content-Type: application/json',
'content' => json_encode($message),
)
);
$resp = file_get_contents($webhook_url, false, stream_context_create($options));
実行すると投稿される
![discord Bot](https://halfpower.work/wp-content/uploads/2022/09/5.png)