目次
検証環境
- Windows 10 Pro 64bit May 2021 Update (21H1)
- Windows 10 Pro 64bit November 2021 Update (21H2) 2022/3/26
- Discord
Discord側の設定
私は以下のWebサイトを参考にしました
詳しくは「Webhook Discode」でググって!!
ウェブフックURLは、下記のPowerShellスクリプトファイル内で使うぞ!!
スクリプトファイル
PowerShellスクリプトファイル(*.ps1)
「Discord_push_sample.ps1」というファイル名で作成
スクリプトファイル内の文字エンコードは「UTF-8(BOM付き)」※必ずBOM付きの必要あり
# ユーザー名(username)
$usernemestr = "usernameテスト"
# 本文内容(content)
$contentstr = "contentテスト1行目\ncontentテスト2行目"
# ウェブフックURL(Webhook URL)
$webhookurl = "https://discord.com/api/webhooks/**************************"
# json文字列を作成して、UTF-8に変換する
$bodyjson = "{`"username`": `"$usernemestr`", `"content`": `"$contentstr`"}"
$body = [System.Text.Encoding]::UTF8.GetBytes($bodyjson)
#Discordに送る
Invoke-WebRequest -Headers @{"Content-Type"="application/json"} -Method Post -Body $body $webhookurl
PowerShellのスクリプトファイル(*.ps1)を実行するバッチファイル
「Discord_push_sample.bat」というファイル名で作成
バッチファイル内の文字エンコードは「Shift-JIS」
「Discord_push_sample.ps1」と「Discord_push_sample.bat」は同じフォルダに置いてね
rem ---------------------------------------
rem 同じフォルダにあるDiscord_push_sample.ps1をpowershellコマンドとして実行
rem
rem [%~dp0]はカレントディレクトリを取得
rem スペース入りファイルパスを想定し["]で囲う
rem ---------------------------------------
set ps1filename="%~dp0Discord_push_sample.ps1"
powershell -ExecutionPolicy Unrestricted -File %ps1filename%
トラックバック URL
https://moondoldo.com/wordpress/wp-trackback.php?p=7165