Send Google Sheets Data to Discord: Apps Script Tutorial

by Fahim Mahmud Chisti

To send Google Sheets data to a Discord channel, you need a Discord webhook URL and a short Apps Script function that posts each row to it. By the end of this tutorial, new rows from your sheet will appear in Discord automatically, as plain messages or colour-coded embeds.

Quick answer: Create a webhook in the Discord channel, save its URL as a script property, and have Apps Script post the row with UrlFetchApp.fetch() as JSON. A trigger then runs the function for you.

  1. In Discord, open the channel’s Edit Channel > Integrations and create a webhook; copy its URL.
  2. In the sheet, open Extensions > Apps Script and save the URL as the script property DISCORD_WEBHOOK_URL.
  3. Paste the script, run it once and approve the permissions.
  4. Check the channel for the message and the log for status 204.
  5. Add an On form submit or time-driven trigger so it runs on its own.
In this guide
  1. Before You Start
  2. How the Sheet Talks to Discord
  3. Step 1: Create a Discord Webhook
  4. Step 2: Save the URL and Paste the Script
  5. Step 3: Run It Once and Check Discord
  6. Step 4: Format the Message as a Rich Embed
  7. Step 5: Run It Automatically With a Trigger
  8. Quotas and Limits to Plan For
  9. Handle Rate Limits and Silent Failures
  10. If It Still Doesn’t Work
  11. Frequently Asked Questions
  12. Next Steps
Dual monitor setup showing Google Sheets data syncing to a Discord channel via Webhooks

Before You Start

  • Discord access: the Manage Webhooks permission on the target channel. Server owners and admins have it.
  • A Google Sheet: headers in row 1 and data from row 2. The scripts read columns A to D of the last row.
  • Time: about 15 minutes, including the trigger.
  • Treat the webhook URL like a password: anyone who has it can post to your channel. If it leaks, delete the webhook in Discord and create a new one.

How the Sheet Talks to Discord

A Discord webhook is a URL that accepts an HTTP POST and turns the JSON body into a channel message. Apps Script, the JavaScript runtime built into Google Sheets, can send that POST with its UrlFetchApp service. No server and no paid automation tool is involved.

The flow is short: a trigger fires, the script reads the newest row, builds a JSON payload, and posts it to the webhook. Tools like Zapier or Make can do the same job without code (see the Zapier vs Make vs n8n comparison), but they add a monthly cost and task limits that a free script does not have.

Step 1: Create a Discord Webhook

  1. Open Discord in your browser or desktop app and go to your server.
  2. Right-click the channel where you want notifications and select Edit Channel.
  3. Click the Integrations tab in the left-hand sidebar.
  4. Click Create Webhook (or View Webhooks if the channel already has one, then add a new one).
  5. Name your webhook (for example “Sheet Notifier”) and copy the generated URL.

For the full list of payload fields, see the official Discord Webhook Documentation.

Step 2: Save the URL and Paste the Script

Open your Google Sheet and go to Extensions > Apps Script. Store the webhook URL first, so it never appears in the code where anyone with access to the script could copy it:

  1. Click the gear icon (Project Settings) in the editor’s left sidebar.
  2. Under Script Properties, add a property named DISCORD_WEBHOOK_URL and paste the URL as its value.
  3. Save, then go back to the Editor (the <> icon).

Replace any template code in Code.gs with the script below. It reads the last row of the sheet and sends it as a plain-text message.

function sendLatestRowToDiscord() {
  const webhookUrl = PropertiesService.getScriptProperties().getProperty("DISCORD_WEBHOOK_URL");
  const sheet = SpreadsheetApp.getActiveSpreadsheet().getActiveSheet();
  const lastRow = sheet.getLastRow();
  // Prevent execution on an empty sheet
  if (lastRow < 2) {
    Logger.log("No data rows found to send.");
    return;
  }
  // Fetch the entire last row
  const lastColumn = sheet.getLastColumn();
  const rowData = sheet.getRange(lastRow, 1, 1, lastColumn).getValues()[0];
  // Format the message payload (Discord allows up to 2,000 characters)
  const message = `🔹 **New Row Added**\n` +
    `**Column A:** ${rowData[0]}\n` +
    `**Column B:** ${rowData[1]}\n` +
    `**Column C:** ${rowData[2]}`;
  const payload = { content: message };
  const options = {
    method: "post",
    contentType: "application/json",
    payload: JSON.stringify(payload),
    muteHttpExceptions: true
  };
  const response = UrlFetchApp.fetch(webhookUrl, options);
  Logger.log(`Status Code: ${response.getResponseCode()}`);
  Logger.log(`Response Body: ${response.getContentText()}`);
}

The script finds the last row with content, reads its values into an array, and builds a message using Discord’s Markdown. It then posts the payload with the UrlFetchApp service.

Step 3: Run It Once and Check Discord

  1. Click Save, pick sendLatestRowToDiscord in the function drop-down at the top of the editor, and click Run.
  2. On the first run, Google asks you to authorize the script. Click Review permissions, choose your account, and allow access. If you see “Google hasn’t verified this app”, click Advanced and continue to your project; it is your own script.
  3. Open the Execution log at the bottom of the editor.

If it worked, the log shows Status Code: 204 with an empty response body; 204 is Discord’s normal reply to a webhook. The last row of your sheet appears in the channel within a few seconds. Any other code means Discord rejected the request, and the response body says why.

Step 4: Format the Message as a Rich Embed

Plain messages get lost in busy channels. A rich embed is a card with a coloured side border, labelled fields, a footer and a timestamp, which is easier to scan.

The script below turns columns A to D (timestamp, task name, assignee, status) into an embed. Paste it into the same Code.gs file under the first function. Check the Discord Embed Limits if your values are long, because oversized embeds are rejected with HTTP 400.

function sendRichEmbedToDiscord() {
  const webhookUrl = PropertiesService.getScriptProperties().getProperty("DISCORD_WEBHOOK_URL");
  const sheet = SpreadsheetApp.getActiveSpreadsheet().getActiveSheet();
  const lastRow = sheet.getLastRow();
  if (lastRow < 2) return;
  const data = sheet.getRange(lastRow, 1, 1, 4).getValues()[0];
  const [timestamp, taskName, assignedTo, status] = data;
  // Discord rejects empty field values and values longer than 1,024 characters
  const text = value => (String(value).trim() || "-").slice(0, 1024);
  // Map statuses to hex colors (converted to decimal)
  const statusColor = status === "Completed" ? 3066993 : 15158332; // Green vs Red
  const embedPayload = {
    embeds: [{
      title: "📝 Task Tracker Update",
      color: statusColor,
      fields: [
        { name: "Task Name", value: text(taskName), inline: true },
        { name: "Assigned To", value: text(assignedTo), inline: true },
        { name: "Status", value: text(status), inline: true }
      ],
      footer: { text: `Sheet Logged: ${new Date(timestamp).toLocaleDateString()}` },
      timestamp: new Date().toISOString()
    }]
  };
  const options = {
    method: "post",
    contentType: "application/json",
    payload: JSON.stringify(embedPayload),
    muteHttpExceptions: true
  };
  const response = UrlFetchApp.fetch(webhookUrl, options);
  const code = response.getResponseCode();
  // Discord answers 204 No Content on success (200 only if you add ?wait=true to the URL)
  if (code < 200 || code >= 300) {
    Logger.log(`Failed to send embed. Code: ${code} Body: ${response.getContentText()}`);
  }
}

Run sendRichEmbedToDiscord once from the editor the same way. A green card appears in Discord when the status column says Completed and a red one for anything else. This function logs only on failure, so an empty log after the run is a good sign.

Step 5: Run It Automatically With a Trigger

A trigger runs the function without you opening the editor. Choose the event that matches how rows reach your sheet:

  • On form submit: best when rows come from a Google Form linked to the sheet. Each submission posts once.
  • Time-driven: best when rows arrive from other tools or the API, which do not fire edit triggers. Note that both scripts above post the last row on every run, so a schedule would repeat the same row until a new one arrives. Store the last row number you sent (for example in a script property) and skip the run when nothing is new.
  • On edit: fires on every edit a person makes, including small corrections, so it can post the same row several times.

To add the trigger:

  1. In the Apps Script editor, click the clock icon (Triggers) in the left sidebar.
  2. Click the Add Trigger button in the bottom right corner.
  3. Select your target function (for example sendRichEmbedToDiscord).
  4. Choose the event source. Select From spreadsheet and On form submit if you collect data with Google Forms, or select Time-driven to run on a schedule.
  5. Save the trigger and authorize the necessary permissions.

To confirm it works, submit a test form entry (or wait for the next scheduled run). Then open Executions in the left sidebar: the run should be listed as Completed, and the message should be in Discord.

Quotas and Limits to Plan For

Each webhook message is one small HTTP request, so runtime is rarely the problem. These are the limits that matter:

  • URL Fetch calls: 20,000 per day for consumer Google accounts and 100,000 per day for Google Workspace accounts
  • Script runtime: 6 minutes per execution
  • Discord message size: 2,000 characters for content; per embed, 256 characters for the title, up to 25 fields, 1,024 characters per field value, and 6,000 characters in total
  • Discord rate limits: each webhook is rate limited; when you exceed the limit Discord answers with HTTP 429 and tells you how long to wait

If a run is slow, check whether your script reads old rows it does not need instead of only the newest one.

Handle Rate Limits and Silent Failures

By default, when UrlFetchApp.fetch() gets a non-2xx status code (such as 429 Too Many Requests or 400 Bad Request), it throws an exception that stops the script. Inside a trigger, you only find out from the Executions page or the failure summary email that Apps Script sends later.

Setting muteHttpExceptions: true in the options lets your code read the error response and act on it. The flip side is that a failed request no longer raises anything, so you must check the status code yourself or the failure really is silent.

The pattern below handles Discord’s rate limiting by reading retry_after (in seconds) from the response body. Use it in place of the single UrlFetchApp.fetch() call and the status check at the end of either function:

const response = UrlFetchApp.fetch(webhookUrl, options);
const responseCode = response.getResponseCode();
if (responseCode === 429) {
  // Discord reports the wait in seconds (it can be a decimal)
  let retryAfterSeconds = 1;
  try {
    retryAfterSeconds = JSON.parse(response.getContentText()).retry_after || 1;
  } catch (err) {
    // Body was not JSON; keep the 1-second default
  }
  Logger.log(`Rate limited by Discord. Retrying after ${retryAfterSeconds}s...`);
  Utilities.sleep(Math.ceil(retryAfterSeconds * 1000));
  // Retry the request once
  UrlFetchApp.fetch(webhookUrl, options);
} else if (responseCode < 200 || responseCode >= 300) {
  Logger.log(`Error ${responseCode}: ${response.getContentText()}`);
}

Empty cells are the other common cause of errors. getValues() returns an empty string for a blank cell, and Discord rejects an embed field with an empty value (HTTP 400). Convert values to strings and substitute a placeholder such as a dash, as the text() helper in the embed script does.

If It Still Doesn’t Work

  • The run fails on the UrlFetchApp.fetch line before Discord answers: the script property is missing, so the URL is empty. Check that the name is exactly DISCORD_WEBHOOK_URL, with no spaces.
  • HTTP 404 from Discord: the webhook was deleted or the URL was copied only partly. Copy it again from the channel’s Integrations tab.
  • HTTP 400 from Discord: the payload broke a rule, usually an empty message, an empty embed field or a value over the size limits. The response body names the field.
  • The trigger posts data from the wrong tab: in a trigger there is no tab open on screen, so getActiveSheet() may not return the tab you expect. Move the target tab to the first position, or change getActiveSheet() to getSheetByName("Your tab name").
  • The trigger never runs: open Triggers and check that it exists and points at the right function. Then check Executions for failed runs and their error messages.

Frequently Asked Questions

Can Google Sheets post to Discord when a new row is added?

Yes, but the right trigger depends on where the row comes from. Rows from a Google Form fire the On form submit trigger. Rows typed by a person fire an edit trigger. Rows added by other apps or the API fire neither, so use a time-driven trigger that remembers the last row it sent.

Why does the script log 204 instead of 200?

Because 204 No Content is Discord’s normal success reply to a webhook: the message was posted and there is nothing to return. If you add ?wait=true to the webhook URL, Discord answers 200 and returns the created message as JSON instead.

Is it safe to share a sheet that has this script?

Yes, as long as the webhook URL is stored as a script property and not in the code. People with edit access to the sheet can still open the script project and its settings, where the property is visible. Share edit access only with people you trust, and recreate the webhook if someone leaves.

How many messages can I send to Discord from Apps Script?

Apps Script allows 20,000 URL fetches a day on a consumer account, which is far more than a busy sheet needs. The tighter limit is Discord’s per-webhook rate limit. For bulk updates, combine several rows into one message instead of sending one request per row.

Next Steps

Once the basic message works, add the retry pattern above so short Discord outages do not drop messages. To send the same rows to other services, such as Slack or your own API, follow the guide on sending webhooks from Google Sheets. For more trigger and quota patterns, see the Google Apps Script automation guide, and for receiving-side concerns such as retries and signatures, the API integrations and webhooks guide.

all_in_one_marketing_tool