Git Product home page Git Product logo

google-sheets-to-discord's Introduction

Google-Sheets-to-Discord

This script will notify you of changes to your google sheet through discord, using a customizable discord embed.

Setup

  1. Go to the script editor on your google sheet
  2. Paste the contents of the main.gs file into the script editor
  3. Open Discord, go to 'Server Settings' > 'Integrations' > 'Webhooks'
  4. Create a 'New Webhook' & fill in all the fields necessary.
  5. Copy the webhook link & paste this link into the "WEBHOOKURL".
  6. In the google sheet script editor, using the left hand side menu, navigate to 'Triggers' and add a new trigger as shown in the image below

Make sure to edit a range to test it.

Additional Options

This section will showcase different options that you can implement to customize your embeds and program behaviour.

Forums Support

With the addition of Discord's new Forum channels, there is the ability to direct your google form responses into individual threads or the same singular thread!

New Forum channel thread for each response

thread_name can be used to specify the name of the thread you want to generate.

{
  "thread_name" : "THREAD TITLE GOES HERE",
  "embeds" :[{
    "title": "TOP TEXT CHANGE THIS IN SCRIPT",
    "fields" : items,
    "color": 16711680
  }]
}

Same Forum channel thread for each response

thread_id can be used to specify the thread you want all responses to go into.

{
  "thread_id" : 1234 //Your thread id goes here! ,
  "embeds" :[{
    "title": "TOP TEXT CHANGE THIS IN SCRIPT",
    "fields" : items,
    "color": 16711680
  }]
}

Program Behaviour

Only watch a certain column

This addition will allow you to only be notified if edits are made in the specified column. This code should be pasted after the var items = []; line.

  // If you only want to watch a certain column
  var column_id = 3
  // If not the column you want to watch
  if (column_id < event.range.getColumn() || column_id > event.range.getLastColumn() ){
      // Do nothing
      return;
  }

Cosmetic

In this section, we will outline the multiple different cosmetic customizations that you can add to your webhook. You can use any combination of the options displayed below.

Colour

This option will allow you to set a colour to your embed. The colour option requires a numerical input instead of hexadecimal. E.g. Red in Hexadecimal is #FF0000. As a decimal, this would be translated into 16711680.

{
  "embeds" :[{
    "title": "TOP TEXT CHANGE THIS IN SCRIPT",
    "fields" : items,
    "color": 16711680
  }]
}

Author

This option adds an author block to the embed. The author block (object) includes three values:

  • name - the name field.
  • url - allows for a hyperlink to be attached to the name.
  • icon_url - avatar displayed.
{
  "embeds" :[{
    "title": "TOP TEXT CHANGE THIS IN SCRIPT",
    "fields": items,
    "author": {
      "name": "AUTHOR NAME CHANGE THIS IN SCRIPT",
      "url": "URL CHANGE THIS IN SCRIPT",
      "icon_url": "ICON URL CHANGE THIS IN SCRIPT"
    }
  }]
}

URL

This option binds a url link to the title of your embed.

{
  "embeds" :[{
    "title": "TOP TEXT CHANGE THIS IN SCRIPT",
    "fields": items,
    "url": "URL CHANGE THIS IN SCRIPT"
  }]
}

Description

Displays a description for the embed.

{
  "embeds" :[{
    "title": "TOP TEXT CHANGE THIS IN SCRIPT",
    "fields": items,
    "description": "DESCRIPTION CHANGE THIS IN SCRIPT"
  }]
}

Image

Displays an image inside of the embed.

{
  "embeds" :[{
    "title": "TOP TEXT CHANGE THIS IN SCRIPT",
    "fields": items,
    "image": {
      "url": "URL CHANGE THIS IN SCRIPT"
    }
  }]
}

Thumbnail

Allows for a thumbnail to be displayed in the embed.

{
  "embeds" :[{
    "title": "TOP TEXT CHANGE THIS IN SCRIPT",
    "fields": items,
    "thumbnail": {
      "url": "URL CHANGE THIS IN SCRIPT"
    }
  }]
}

Footer icon

An optional customization you can make to footer text, is to add an icon image which will be displayed next to it.

{
  "embeds" :[{
    "title": "TOP TEXT CHANGE THIS IN SCRIPT",
    "fields": items,
    "footer": {
      "text": "BOTTOM TEXT CHANGE THIS IN SCRIPT",
      "icon_url": "URL CHANGE THIS IN SCRIPT"
    }
  }]
}

google-sheets-to-discord's People

Contributors

kelo avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

google-sheets-to-discord's Issues

Possible to limit triggers?

This script works great, but is it possible to limit the triggers within a timeframe?

In my case, I want a maximum of one trigger every 24 hours. So if any cell in the sheet is edited, it will post to Discord, but there will be a 24 hour cooldown before the next post.

I essentially want a notification saying the sheet was updated, but I'm not looking to spam messages if numerous edits are made.

Enhacement rather than issue!

This script is great thank you. The spreadsheet that I'm using it on will be routinley populated with a new row where I'd like to call out just the values in Column2 (ColB) and Column28 (ColAB). I wondering if there is a way to tweak this line and the associated variables to display just these values on the Discord notification?

"value": "Name: "+ ColB +"\nGrand Total: " + ColAB + "\nEdit made: "+ reason,

Many thanks in advance!

Edit range to?

Hi,

I have no experience with code but I am trying to figure this out and have gotten stumped. I have completed all the steps needed but the execution log shows this:

image

I have seen I need to edit "range" but I'm unsure what this actually means, any help would be great!

TypeError

hi there :)

when is start the script i become that error

TypeError: Cannot read property 'range' of undefined onEdit @ main.gs:4

how can i fix that?

How to only trigger when changing a certain column

Hi there, thank you so much for this script :)

I am trying to make it so that changes in only a certain column ("C" or the third column on my spreadsheet) triggers a message on Discord.

I added your code after var items = [];

  // If you only want to watch a certain column
  var column_id = 3
  // If not the column you want to watch
  if (column_id < event.range.getColumn() || column_id > event.range.getLastColumn ){
      // Do nothing
      return;
  }

However, it still is triggered to send a message if I change any cell on the spreadsheet, not just the third column. How do I specify that I only want the third column to be triggered? I tried doing var column_id = "C" but it didn't recognize that as anything so I am probably misunderstanding how to do this xD

Thank you again!

This code works wonderfully, but I have a question about pasted data

Thank you so much for sharing this, it has helped me tremendously for the task I was trying to accomplish. It performs the purpose I need when the target column has manual edits to individual cells to notify on each cell change.

But when I try to paste a full column worth of data, it is not triggering. Is there a way to get edit the code to allow for pasted data into the target cell or column range specificed?

Cannot read properties of 'undefined'

Hi,
I've set up everything as instructed but I can't get the code to get triggered. The error I get is as below:

TypeError: Cannot read properties of undefined (reading 'range')
onEdit	@ EditNotif.gs:4

What am I doing wrong?
Thanks

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.