前提
GASを利用してGmailをDiscordに転送したいのですが、添付ファイルや写真を転送できません。
こちらの記事は参考にしました。
実現したいこと
Gmailの特定のラベル内全メールを添付ファイルや写真を含め、Discordに転送するbotを実装したいです。
発生している問題・エラーメッセージ
エラーメッセージは表示されませんが、特定のラベル内全メールの転送されるのが差出人、メールアドレス、タイトル、本文で、添付ファイル、写真が転送されません。
コード全体
GAS
1function hook(){ 2 var query = "label:label2 label:unread"; 3 var threads = GmailApp.search(query); // 未読のスレッドを取得 4 5 if (threads.length == 0) { 6 Logger.log('新規メッセージなし'); 7 return 8 } 9 10 threads.forEach(function (thread) { 11 const messages = thread.getMessages(); 12 13 const payloads = messages.map(function (message) { 14 message.markRead(); // メールを既読に設定する 15 16 const from = message.getFrom(); 17 const subject = message.getSubject(); 18 const plainBody = message.getPlainBody(); 19 const attachment = message.getAttachments(); 20 21 const webhook = getWebhookUrl(); 22 23 Logger.log(subject); 24 const payload = { 25 embeds: [{ 26 title: subject, 27 author: { 28 name: from, 29 }, 30 description: plainBody.substr(0, 2048), 31 attachments: attachment, 32 }], 33 } 34 return { 35 url: webhook, 36 contentType: 'application/json', 37 payload: JSON.stringify(payload), 38 } 39 }) 40 41 Logger.log(payloads); 42 UrlFetchApp.fetchAll(payloads); 43 }) 44} 45 46 47function getWebhookUrl() { 48 const spreadsheet = SpreadsheetApp.getActiveSpreadsheet(); 49 const sheet = spreadsheet.getActiveSheet(); 50 51 return sheet.getRange(1, 1).getValue(); // セルA1を取得 52}
試したこと
GAS
1const attachment = message.getAttachments(); 2// 途中を省略しています。 3const payload = { 4 embeds: [{ 5 title: subject, 6 author: { 7 name: from, 8 }, 9 description: plainBody.substr(0, 2048), 10 attachments: attachment, 11 }], 12 } 13
こちらのpayload内の記入に誤りがあると仮定しております。
Discordのディベロッパーポータルも確認しましたが、JS等の予備知識がほぼ無く、コピペを多用している状態ですので、内容が理解できませんでした。
添付ファイル、写真を含めたかたちで転送できるコードを教えていただきたいです。
見当違いな点も多々見受けられると思いますが、ご回答よろしくお願いいたします。

バッドをするには、ログインかつ
こちらの条件を満たす必要があります。
2022/11/06 12:47
2022/11/07 01:56