Chart from Google sheet to Discord

Hey there,

I have a graph on Google Sheets with all my investments and the daily evolution of each of them, I would like to share this evolution every day on my discord server automatically.

This means that the values change every day and that this must be done automatically in the script.

Is this possible? How can I do ?

The easiest way to do this is probably to write an AppScript that sends a POST request to a Discord webhook. The POSTed message can include a QuickChart image URL. Set the script to run on a daily trigger.

The script would look something like this, but it depends on what your sheet looks like:

function postChartToDiscord() {
  var webhookUrl = 'YOUR_DISCORD_WEBHOOK_URL';
  var sheet = SpreadsheetApp.getActiveSpreadsheet().getActiveSheet();
  var dataRange = sheet.getDataRange();
  var data = dataRange.getValues();
  
  // Example: Process your data here and generate the chart URL
  var chartData = {
    type: 'line',
    data: {
      labels: data[0].slice(1), // Assuming the first row as labels
      datasets: [{
        label: data[1][0], // Dataset label is first value
        data: data[1].slice(1), // Data values are the remaining
        fill: false,
      }]
    },
    options: {
      title: {
        display: true,
        text: 'My investments'
      }
    }
  };
  
  var chartUrl = 'https://quickchart.io/chart?c=' + encodeURIComponent(JSON.stringify(chartData));
  
  // Prepare the Discord message
  var discordMessage = {
    content: "Here's the daily evolution of my investments:",
    embeds: [{
      image: {
        url: chartUrl
      }
    }]
  };
  
  // Send the message to Discord
  var options = {
    method: 'post',
    contentType: 'application/json',
    payload: JSON.stringify(discordMessage),
    muteHttpExceptions: true
  };
  
  UrlFetchApp.fetch(webhookUrl, options);
}