你是不是也常常一忙就忘記喝水呢?今天,我們來動手做一個簡單又實用的 Discord 通知器,它會在指定的時間自動發送可愛的提醒訊息,關心你和頻道裡的每一個人
在固定的時間與間隔內,自動傳送提醒訊息
設定排程時間:決定什麼時候要發送提醒
建立內容的資料:寫下幾句溫馨的提醒語錄
傳送提醒訊息:將訊息自動傳送到你的 Discord 頻道
點選右上角的「Create Workflow」來建立新的流程
點下畫布正中間的「Add first step」
選擇排程「On a schedule」
選擇「Custom Cron」來更彈性地設定時間
指令內容填入以下內容,代表平日的 09:00~17:00 每個小時會觸發
0 9-17 * * 1-5
接著到這個流程的「Settings」裡面
將時區「Timezone」設定為台灣時間,這樣才會在正確的時間下去跑
下個節點選擇「Code」,來寫簡單的程式碼
貼上底下的程式碼,意思是會去隨機從變數「messages」裡面取一條出來當訊息
const messages = [
"🔔 喝水時間到囉!快去補充水分!",
"💻 電腦看太久了,起來伸個懶腰,順便喝杯水吧!",
"💧 身體的 70% 是水,你今天補充了嗎?",
"嘿!你最好的朋友「水」在呼喚你!",
"休息是為了走更長遠的路,喝水也是!"
];
// 隨機選出一句話
const selectedMessage = messages[Math.floor(Math.random() * messages.length)];
// 將選出的話放進物件,並用陣列包起來回傳
return [{
json: {
randomMessage: selectedMessage
}
}];
下個節點選擇「Discord」
選擇「Send a message」
類型選擇「Webhook」
建立 Discord 憑證
打開 Discord 頻道的設定,選擇「整合」→「建立 Webhook」
點選「複製網址」
把我們左邊上個節點的變數,拖拉到「Message」的欄位裡面
點選上方的「Execute step」測試看看,輸出「true」代表成功惹
Discord 也有出現訊息
畫布上面完整的流程會長這樣,記得上方存檔以及要切換為「Active」才會開始運作哦
最後附上流程的 JSON 檔案,如果懶得製作也可以直接匯入使用
{
"name": "飲水提醒",
"nodes": [
{
"parameters": {
"rule": {
"interval": [
{
"field": "cronExpression",
"expression": "0 9-17 * * 1-5"
}
]
}
},
"type": "n8n-nodes-base.scheduleTrigger",
"typeVersion": 1.2,
"position": [
0,
0
],
"id": "da9403af-f3f5-4783-9613-69f164b60d47",
"name": "Schedule Trigger"
},
{
"parameters": {
"jsCode": "const messages = [\n \"🔔 喝水時間到囉!快去補充水分!\",\n \"💻 電腦看太久了,起來伸個懶腰,順便喝杯水吧!\",\n \"💧 身體的 70% 是水,你今天補充了嗎?\",\n \"嘿!你最好的朋友「水」在呼喚你!\",\n \"休息是為了走更長遠的路,喝水也是!\"\n];\n\n// 隨機選出一句話\nconst selectedMessage = messages[Math.floor(Math.random() * messages.length)];\n\n// 將選出的話放進物件,並用陣列包起來回傳\nreturn [{\n json: {\n randomMessage: selectedMessage\n }\n}];"
},
"type": "n8n-nodes-base.code",
"typeVersion": 2,
"position": [
220,
0
],
"id": "a4aeb86e-37a1-4f06-9265-99dac20e4cae",
"name": "Code"
},
{
"parameters": {
"authentication": "webhook",
"content": "={{ $json.randomMessage }}",
"options": {}
},
"type": "n8n-nodes-base.discord",
"typeVersion": 2,
"position": [
440,
0
],
"id": "26b38611-8da9-46e9-afa5-76aee7815ae0",
"name": "Discord"
}
],
"pinData": {},
"connections": {
"Schedule Trigger": {
"main": [
[
{
"node": "Code",
"type": "main",
"index": 0
}
]
]
},
"Code": {
"main": [
[
{
"node": "Discord",
"type": "main",
"index": 0
}
]
]
}
},
"active": true,
"settings": {
"executionOrder": "v1",
"timezone": "Asia/Taipei",
"callerPolicy": "workflowsFromSameOwner",
"executionTimeout": -1
},
"versionId": "d403fc95-2131-4ef0-acde-43525b233301",
"meta": {
"templateCredsSetupCompleted": true
},
"id": "DN78At8wNA7KDqTQ",
"tags": []
}
匯入的方式:到上方點選「Import from File…」