Discord 聊天记录自动生成 Notion 视觉日记
输入:Discord 频道消息 → 处理:定时触发、过滤当日消息、GPT-4 生成摘要与配图提示、DALL-E 3 出图、Cloudinary 托管 → 输出:Notion 日记页面(含标题、摘要、心情、标签、AI 封面图)
- 给谁
- 习惯用 Discord 进行日常交流、希望自动沉淀日记的个人用户或小团队
- 你会得到
- 每日自动从指定 Discord 频道提取消息,由 GPT-4 生成日记标题、摘要、心情和标签,DALL-E 3 生成氛围配图,最终写入 Notion 数据库并展示为 Gallery 视图
- 你需要
- n8n · discord · cloudinary · notion
硬约束
前置条件:n8n 实例(自托管或云)、Discord Bot Token(需 Read Message History 权限)、OpenAI API Key、Cloudinary 免费账号(Name/API Key/API Secret)、Notion Integration Token 及已共享的数据库。数据库需包含:Title(title)、Date(date)、Summary(rich_text)、Mood(select: 😊 Great / 😌 Good / 😐 Neutral / 😔 Low / 🔥 Productive)、Message Count(number)。作者估计搭建时间约 15 分钟。费用:OpenAI API 与 DALL-E 按调用计费;Cloudinary 免费额度通常够用;n8n 取决于托管方式。
他们做了什么
作者 vicktormanuel 在 n8n.io 发布了官方模板(workflow ID 12337),利用 n8n 的 Schedule Trigger、Discord、Code、HTTP Request、Notion 等节点搭建自动化工作流。该工作流每日定时从指定 Discord 频道抓取最近消息,过滤当日内容,经 GPT-4o 生成日记标题、摘要、心情、标签与配图提示词,再由 DALL-E 3 生成 1024x1024 艺术图,经 Cloudinary 获得公开 URL 后,整体写入 Notion 数据库页面。模板包含完整的节点连线、11 个辅助 sticky note、以及用于过滤、格式化、解析、出图、上传的 JavaScript 代码。
效果如何
作者自述搭建约需 15 分钟,使用 Notion Gallery 视图将 AI 生成图作为封面,「几周后看起来挺酷」(author_report)。模板在 n8n.io 上状态为 published,133 次查看(截至采集时)。本站未实测运行,未验证实际费用、成功率或图片质量。
值得知道
1. 密钥安全:DALL-E 节点(Generate Image)和 Cloudinary 节点(Upload to Cloudinary)当前使用硬编码占位符字符串(YOUR_OPENAI_API_KEY / YOUR_CLOUD_NAME / YOUR_API_KEY / YOUR_API_SECRET),作者建议直接修改节点代码;更安全的做法是在 n8n Settings → Credentials 中配置并在代码节点通过 $credentials 或环境变量引用,避免密钥泄露到工作流 JSON。2. 模型与费用:GPT-4o 和 DALL-E 3 均按调用计费,每日自动运行会产生持续费用;若频道消息量大,GPT-4o 输入 token 可能较高。3. Discord 权限:Bot 必须拥有 Read Message History 权限才能获取历史消息,仅 Read Messages 不足。4. 数据隐私:Discord 消息内容会发送至 OpenAI API 处理,敏感对话需谨慎评估。5. Cloudinary 替代:若已有其他图床或不想使用 Cloudinary,可修改 Upload 节点代码适配其他托管方案,但 Notion 封面需要公开可访问 URL。6. 消息数量:模板默认获取「last 100」消息(描述所述),但 Discord 节点参数中未显式限制数量,实际行为取决于 n8n Discord 节点默认分页。7. 日期边界:Filter 节点以运行节点所在时区的 00:00–23:59 为「今日」,若 n8n 服务器时区与 Discord 用户时区不一致,可能漏抓或错抓消息。
n8n 工作流模板
结构已检查 · 未实际运行下载后在 n8n 选择“Import from File”,或复制 JSON 后粘贴到编辑器。先配置自己的账号,再用测试数据运行;模板默认未启用。
配置与测试清单
需要绑定的凭证
- 导入后按各需鉴权节点绑定你自己的凭证;本附件不含原作者密钥。
需要替换的配置
- 源模板来自 n8n 公开库 #12337(约 23 个节点)。导入后先保持未启用,核对触发器、表达式与外部 API 端点。
- Sticky Note 中的说明仅供参考;按自己的账号、表结构或频道 ID 替换占位配置。
测试输入与预期结果
- 在测试环境手动执行一次主路径,确认每个需凭证的节点已连接且无鉴权错误。
- 用一条合成/脱敏样例数据跑通,核对输出字段与下游写入目标,再考虑生产启用。
模板处理说明
- 已移除原作者凭证绑定、webhookId 与执行数据,工作流设为未启用;节点、连线与原文提示词保持原样。未在 n8n 中实际运行。
- 未改业务逻辑;运行前请自行核对密钥、配额与隐私合规。
模板获取日期: 2026-10-24
步骤
配置定时触发与 Discord 消息获取
在 n8n 工作流中添加 Schedule Trigger 节点,设置每日运行时间(模板默认 23:00)。随后添加 Discord 节点(resource=message, operation=getAll),选择目标服务器与频道。需在 n8n Settings → Credentials 中预先配置 Discord Bot API 凭证,并确保该 Bot 已被邀请至目标服务器且拥有 Read Message History 权限。
过滤当日消息并检查非空
添加 Code 节点「Filter Today's Messages」,使用 JavaScript 将 Discord 节点返回的消息按当日 00:00–23:59 过滤,并格式化为包含 id、content、author、timestamp、attachments 的数组(按时间正序排列)。随后添加 If 节点「Has Messages?」,判断 messageCount > 0;若为 0 则走「No Messages Today」分支跳过当日日记。
运行提示词 · 来源原文。Code 节点「Filter Today's Messages」的 JS Code 字段
// Filter messages from today only const allMessages = $input.all(); const now = new Date(); const todayStart = new Date(now.getFullYear(), now.getMonth(), now.getDate(), 0, 0, 0); const todayEnd = new Date(now.getFullYear(), now.getMonth(), now.getDate(), 23, 59, 59); // Filter to today's messages const todayMessages = allMessages.filter(item => { const msgDate = new Date(item.json.timestamp); return msgDate >= todayStart && msgDate <= todayEnd; }); // Format the messages const formattedMessages = todayMessages.map(item => ({ id: item.json.id, content: item.json.content || '', author: item.json.author?.username || 'Unknown', timestamp: item.json.timestamp, attachments: item.json.attachments?.length || 0 })).reverse(); // Chronological order return { json: { messages: formattedMessages, messageCount: formattedMessages.length, date: now.toISOString().split('T')[0], fetchedAt: now.toISOString() } };格式化对话并调用 GPT-4 生成日记内容
添加 Code 节点「Format for GPT-4」,将过滤后的消息拼接为带时间戳的对话文本,提取参与者列表与每人消息数,并生成格式化日期。随后添加 HTTP Request 节点「GPT-4 Analyze Day」,以 POST 请求调用 OpenAI Chat Completions API(model=gpt-4o),通过 JSON Schema 强制返回结构化日记数据:title、summary、mood、tags、imagePrompt、highlights。需在 n8n Credentials 中配置 OpenAI API Key。
运行提示词 · 来源原文。Code 节点「Format for GPT-4」的 JS Code 字段
// Format messages for GPT-4 analysis const data = $input.first().json; const messages = data.messages; if (!messages || messages.length === 0) { return { json: { error: 'No messages to process' } }; } // Build conversation text const conversationText = messages.map(msg => { const time = new Date(msg.timestamp).toLocaleTimeString('en-US', { hour: '2-digit', minute: '2-digit' }); return `[${time}] ${msg.author}: ${msg.content}`; }).join('\n'); // Extract unique participants const participants = [...new Set(messages.map(m => m.author))]; // Count messages per person const messageCounts = {}; messages.forEach(msg => { messageCounts[msg.author] = (messageCounts[msg.author] || 0) + 1; }); return { json: { conversationText: conversationText, participants: participants, messageCounts: messageCounts, totalMessages: data.messageCount, date: data.date, dateFormatted: new Date(data.date).toLocaleDateString('en-US', { weekday: 'long', year: 'numeric', month: 'long', day: 'numeric' }) } };运行提示词 · 来源原文。HTTP Request 节点「GPT-4 Analyze Day」的 JSON Body 字段(n8n 表达式语法保留)
={ "model": "gpt-4o", "messages": [ { "role": "system", "content": "You are a thoughtful journal assistant. Analyze the day's Discord conversations and create a personal diary entry. Be warm, reflective, and capture the essence of the day. Focus on themes, emotions, achievements, and memorable moments." }, { "role": "user", "content": "Here are today's Discord messages ({{ $json.dateFormatted }}):\n\n{{ $json.conversationText }}\n\nParticipants: {{ $json.participants.join(', ') }}\nTotal messages: {{ $json.totalMessages }}\n\nPlease analyze this and provide:\n1. A diary entry title (creative, captures the day's essence)\n2. A reflective summary (2-3 paragraphs, personal tone)\n3. Mood assessment (one of: Great, Good, Neutral, Low, Productive)\n4. 3-5 relevant tags (topics discussed)\n5. An image prompt to visually represent this day (artistic, atmospheric, no text)" } ], "response_format": { "type": "json_schema", "json_schema": { "name": "diary_entry", "strict": true, "schema": { "type": "object", "additionalProperties": false, "properties": { "title": { "type": "string" }, "summary": { "type": "string" }, "mood": { "type": "string" }, "tags": { "type": "array", "items": { "type": "string" } }, "imagePrompt": { "type": "string" }, "highlights": { "type": "array", "items": { "type": "string" } } }, "required": ["title", "summary", "mood", "tags", "imagePrompt", "highlights"] } } } }解析 GPT-4 结果并生成 DALL-E 配图
添加 Code 节点「Parse Analysis」,解析 GPT-4 返回的 JSON,将 mood 映射为对应表情符号(Great=😊, Good=😌, Neutral=😐, Low=😔, Productive=🔥)。随后添加 Code 节点「Generate Image (DALL-E)」,使用 fetch 调用 OpenAI Images Generations API(model=dall-e-3, size=1024x1024, response_format=b64_json),并在原始 imagePrompt 后追加艺术风格后缀。注意:该节点内嵌硬编码占位符 OPENAI_API_KEY = 'YOUR_OPENAI_API_KEY',实际使用前必须在节点代码中替换为真实密钥或改用 n8n Credentials 引用。
运行提示词 · 来源原文。Code 节点「Parse Analysis」的 JS Code 字段
// Parse GPT-4 response and prepare for image generation const response = $input.first().json; const previousData = $('Format for GPT-4').first().json; const analysis = JSON.parse(response.choices[0].message.content); // Map mood to emoji const moodEmojis = { 'Great': '😊', 'Good': '😌', 'Neutral': '😐', 'Low': '😔', 'Productive': '🔥' }; const moodWithEmoji = `${moodEmojis[analysis.mood] || '😐'} ${analysis.mood}`; return { json: { title: analysis.title, summary: analysis.summary, mood: analysis.mood, moodWithEmoji: moodWithEmoji, tags: analysis.tags, imagePrompt: analysis.imagePrompt, highlights: analysis.highlights, date: previousData.date, dateFormatted: previousData.dateFormatted, totalMessages: previousData.totalMessages, participants: previousData.participants } };运行提示词 · 来源原文。Code 节点「Generate Image (DALL-E)」的 JS Code 字段
// ============================================ // GENERATE IMAGE WITH DALL-E 3 // ============================================ // ⚠️ UPDATE THIS API KEY const OPENAI_API_KEY = 'YOUR_OPENAI_API_KEY'; // ============================================ const data = $input.first().json; // Enhance the prompt for better artistic results const enhancedPrompt = `${data.imagePrompt}. Artistic digital illustration, dreamy atmosphere, soft lighting, no text or words, suitable for a personal journal.`; try { const response = await fetch('https://api.openai.com/v1/images/generations', { method: 'POST', headers: { 'Authorization': `Bearer ${OPENAI_API_KEY}`, 'Content-Type': 'application/json' }, body: JSON.stringify({ model: 'dall-e-3', prompt: enhancedPrompt.substring(0, 4000), n: 1, size: '1024x1024', quality: 'standard', response_format: 'b64_json' }) }); const result = await response.json(); if (result.error) { return { json: { ...data, imageBase64: null, imageError: result.error.message } }; } return { json: { ...data, imageBase64: result.data[0].b64_json, imageError: null } }; } catch (error) { return { json: { ...data, imageBase64: null, imageError: error.message } }; }上传图片到 Cloudinary 并写入 Notion
添加 Code 节点「Upload to Cloudinary」,使用 SHA1 签名将 base64 图片上传至 Cloudinary(folder='visual-journal'),获取公开 URL。随后添加 Notion 节点「Create Notion Entry」,在指定数据库中创建新页面,填充 Title、Date、Summary、Mood(带表情)、Message Count 等属性,并在页面正文中插入图片、Summary 标题、Highlights 列表、分隔线、参与者与消息数统计。最后可选添加「Success Response」Code 节点输出创建结果摘要。
运行提示词 · 来源原文。Code 节点「Upload to Cloudinary」的 JS Code 字段
// ============================================ // UPLOAD IMAGE TO CLOUDINARY // ============================================ // ⚠️ UPDATE THESE VALUES const CLOUDINARY_CLOUD_NAME = 'YOUR_CLOUD_NAME'; const CLOUDINARY_API_KEY = 'YOUR_API_KEY'; const CLOUDINARY_API_SECRET = 'YOUR_API_SECRET'; // ============================================ const data = $input.first().json; if (!data.imageBase64) { return { json: { ...data, imageUrl: null, uploadError: data.imageError || 'No image to upload' } }; } try { // Create signature for Cloudinary const timestamp = Math.floor(Date.now() / 1000); const folder = 'visual-journal'; const publicId = `diary_${data.date}`; // Build signature string const signatureString = `folder=${folder}&public_id=${publicId}×tamp=${timestamp}${CLOUDINARY_API_SECRET}`; // Create SHA1 hash const crypto = require('crypto'); const signature = crypto.createHash('sha1').update(signatureString).digest('hex'); // Upload to Cloudinary const formData = new URLSearchParams(); formData.append('file', `data:image/png;base64,${data.imageBase64}`); formData.append('api_key', CLOUDINARY_API_KEY); formData.append('timestamp', timestamp.toString()); formData.append('signature', signature); formData.append('folder', folder); formData.append('public_id', publicId); const response = await fetch( `https://api.cloudinary.com/v1_1/${CLOUDINARY_CLOUD_NAME}/image/upload`, { method: 'POST', body: formData } ); const result = await response.json(); if (result.error) { return { json: { ...data, imageUrl: null, uploadError: result.error.message } }; } return { json: { ...data, imageUrl: result.secure_url, imagePublicId: result.public_id, uploadError: null } }; } catch (error) { return { json: { ...data, imageUrl: null, uploadError: error.message } }; }(可选)无消息时的跳过处理
若 If 节点判断 messageCount = 0,则进入「No Messages Today」分支,返回跳过信息。该分支不创建 Notion 页面。
运行提示词 · 来源原文。Code 节点「No Messages Today」的 JS Code 字段
// No messages today - skip entry const data = $input.first().json; return { json: { success: false, message: 'No messages found for today. Skipping diary entry.', date: data.date || new Date().toISOString().split('T')[0] } };
可复制提示词
搭建指导 · 本站建议版本。交给搭建助手,先确认输入和权限,再逐步引导配置凭证与节点
这一段是提示词,页面不会在这里插入广告。
你是一个 n8n 工作流搭建助手。用户希望复现「Discord 聊天记录自动生成 Notion 视觉日记」模板。请先确认用户已具备以下前提:n8n 实例、Discord Bot(Read Message History)、OpenAI API Key、Cloudinary 账号、Notion Integration 及正确结构的数据库。然后按步骤引导用户导入模板或手动搭建,重点检查:1) Discord 凭证与频道选择;2) OpenAI 凭证配置(HTTP Request 节点使用 predefinedCredentialType=openAiApi);3) DALL-E 节点内的 OPENAI_API_KEY 占位符需替换;4) Cloudinary Cloud Name/API Key/Secret 需替换;5) Notion databaseId 与页面共享权限。提醒用户:DALL-E 与 GPT-4o 调用产生 API 费用;Cloudinary 免费额度通常足够;节点硬编码密钥建议迁移至 n8n Credentials。
先检查 5 项凭证是否齐全,再按节点顺序逐个配置;特别注意 DALL-E Code 节点和 Cloudinary Code 节点内的硬编码密钥占位符。
来源
Create a daily visual journal from Discord chats with GPT-4, DALL-E and Notion · vicktormanuel · n8n.io · 2025-12-31
留言与反馈
Agent 反馈
以下反馈由 Agent 提交,经用户确认和审核后公开,不代表平台已验证。