Gmailの特定のラベルをDiscordに転送するbotを実装したいとおもい、検索するとこちらのページが見つかりました。このページにある通りにGASで入力後実行してみると、件名と内容は表示されますが添付ファイルは送信されませんでした。添付ファイルのPDFには大学のZoom講義のリンクが貼られており、本文よりもむしろ添付ファイルのほうが重要なのでどうにかして改善しようとしましたが、ネットで検索しても解決策がわかりませんでした。
Twitterで検索しましたが、こちらのツイートの画像のように添付ファイルが送信されることが理想です。
書き込んだコードは以下の通りです。(上のページの内容とほぼ同じです)
GoogleAppsScript
1function hook() { 2 const threads = GmailApp.search('label:Schedule'); 3 4 if (threads.length == 0) { 5 Logger.log('新規メッセージなし'); 6 return 7 } 8 9 threads.forEach(function (thread) { 10 const messages = thread.getMessages(); 11 12 const payloads = messages.map(function (message) { 13 message.markRead(); // メールを既読に設定する 14 15 const from = message.getFrom(); 16 const subject = message.getSubject(); 17 const plainBody = message.getPlainBody(); 18 19 const webhook = getWebhookUrl(); 20 21 Logger.log(subject); 22 const payload = { 23 content: subject, 24 embeds: [{ 25 title: subject, 26 author: { 27 name: from, 28 }, 29 description: plainBody.substr(0, 2048), 30 }], 31 } 32 return { 33 url: webhook, 34 contentType: 'application/json', 35 payload: JSON.stringify(payload), 36 } 37 }) 38 39 Logger.log(payloads); 40 UrlFetchApp.fetchAll(payloads); 41 }) 42} 43 44 45function getWebhookUrl() { 46 const spreadsheet = SpreadsheetApp.getActiveSpreadsheet(); 47 const sheet = spreadsheet.getActiveSheet(); 48 49 return sheet.getRange(1, 1).getValue(); // セルA1を取得 50}
おそらくは
GoogleAppsScript
1messages.getAttachments();
を上のコードのどこかに挿入するのではないかと思うのですが、どのようなコードを追記すればこちらのツイートの画像のようにできますでしょうか。ご教示くださりますと幸いです。

回答1件
あなたの回答
tips
プレビュー
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。