Home>

What you want to do, what you don't understand
I'd like to use GAS to send the contents of a Google Spreadsheet to discord.
I don't know how to change the icon image of the bot.

Please tell me who knows what kind of code can be created.

The code below

actually works fine and I can send text to discord, but only the icon is in the default state.

actual code

discord ()
};;
function get_value () {
  var sheet1= get_sheet ('spreadsheet URL1', 0);
    var datecoord= sheet1.getRange (2,3);
    var date= datecoord.getValue ();
      //format format
    var formatcoord= sheet1.getRange (3, 3);
    var format= formatcoord.getValue ();
    var messages_array= []; //initialize
    //var lastRow= sheet1.getLastRow ()-10;
    //console.log (lastRow);
  for (let i= 11; i <
= 16; i ++) {
    var timecoord= sheet1.getRange (i, 6);
    var haisintime= timecoord.getValue ();
    var message='None'
    if (haisintime >
 0) {
      var message= Function ('var date='+ date +'; var haisintime='+ haisintime +'; return' + format +';') ();
      }
    messages_array.push (message); //push
  }
  return messages_array; //return
};;
//google spreadsheet automatic transmission
function get_sheet (gss_url, sheet_num) {
  var ss= SpreadsheetApp.openByUrl (gss_url);
  var sheet= ss.getSheets () [sheet_num];
  return sheet;
};;
function get_sheet2 (gss_url, sheet_num) {
  var discord= SpreadsheetApp.openByUrl (gss_url);
  var sheet2= discord.getSheets () [sheet_num];
  return sheet2;
};;
function discord (message) {
    var sheet2= get_sheet2 ('spreadsheet URL2', 0);
    var messages= get_value (); //call get_value () at here
    var lastRow2= sheet2.getLastRow (); //Get last row
    for (let j= 11; j <
= lastRow2; j ++) {
      //webhook
      var webhookcoord= sheet2.getRange (j, 3);
      var webhook= webhookcoord.getValue ();
    //token
      var tokencoord= sheet2.getRange (j, 4);
      var dtoken= tokencoord.getValue ();
  //channel
      var channelcoord= sheet2.getRange (j, 2);
      var dchannel= channelcoord.getValue ();
    //format format
      const url= webhook;
      const token= dtoken;
      const channel= dchannel;
      const text= messages [j-11];
      if (text==='None') {
        console.log (channel + ": No transmission");
        continue; continue;
      }
      const username='bot name';
      const parse='full';
      const method='post';
      const payload= {
          'token': token,
          'channel': channel,
          "content": text,
          'username': username,
          'parse': parse,
      };;
      const params= {
          'method': method,
          'payload': payload,
          'muteHttpExceptions': true
      };;
      Utilities.sleep (500);
    response= UrlFetchApp.fetch (url, params);
    //Execution log
    console.log (channel + ":" + text);
    }
}

Tried
I added const icon= "https://github.com/qiita.png" to the discord () function, but there was no change.


const username='bot name';
      const icon= "https://github.com/qiita.png";
      const parse='full';
      const method='post';
      const payload= {
          'token': token,
          'channel': channel,
          "content": text,
          'icon': icon,
          'username': username,
          'parse': parse,