LogoSynergy

Google Form Submission Banner

Google Form Response To Discord Channel

This guide will show you how to automatically send responses from your Google Form to a Discord Forum channel. It's a simple process that requires some initial setup but after the setup it works automatically.

Google Form Response To Discord Channel example


Step 1 - Create a Google Form

Create a new google form by clicking here

Create a Google Form


Step 2 - Open the Script Editor

Open the Script Editor


Step 3 - Paste the JavaScript Code

Copy and paste the code (given below) into your Script Editor

Paste the JavaScript Code

Javascript Code for Automation
// Ensure that you insert the forum channel's webhook URL where it says webhook_url and keep the '?wait=true' extension after the webhook URL without any spaces; this is the destination where the embed has to be sent.
var WEBHOOK_URL = "webhook_url?wait=true"; // Insert webhook url here
var webhookUsername = "Forms Manager"; // Set webhook username
 
// The post title will be in this format: Applicants_Name's Moderator Application
// For Example: Clyde's Demo Form
var postTitle = "'s Demo Form"; // Set post title
var embedColor = "#27272F"; // Set embed color to whatever color you want or keep it as it is.
 
// Optional fields are pre-filled with dummy data, but you can leave them blank by simply deleting the text within quotation marks (""). This will ensure they don't appear in the final Discord embed.
var messageContent = "Demo Content"; // Set embed content [Optional]
var authorName = "@clyde"; // Set embed author name [Optional]
var authorNameURL = "https://discord.com/invite/E4KRWJW49B"; // Set a hyperlink to be attached to the name [Optional]
var authorIconURL = "https://cdn.discordapp.com/avatars/1081004946872352958/a_6170487d32fdfe9f988720ad80e6ab8c.webp?size=160"; // Set embed author icon [Optional]
var embedTitle = "Demo Embed Title"; // Set embed title [Optional]
var embedTitleURL = "https://dynasticcreator.carrd.co/"; // Set embed title URL [Optional]
var embedDescription = "Demo Embed Description"; // Set embed description [Optional]
var thumbnailURL = "https://cdn.discordapp.com/avatars/1081004946872352958/a_6170487d32fdfe9f988720ad80e6ab8c.webp?size=160"; // Set embed thumbnail [Optional]
var imageURL = "https://cdn.discordapp.com/avatars/1081004946872352958/a_6170487d32fdfe9f988720ad80e6ab8c.webp?size=160"; // Set embed image [Optional]
var footerText = "Demo Embed Footer"; // Set embed footer [Optional]
var footerIconURL = "https://cdn.discordapp.com/avatars/1081004946872352958/a_6170487d32fdfe9f988720ad80e6ab8c.webp?size=160"; // Set embed footer icon [Optional]
 
// WARNING: DO NOT ALTER CODE BELOW THIS UNLESS YOU KNOW WHAT YOU ARE DOING!!
var name = "";
var thread_id = "";
 
// onSubmit function that should be triggered when a new form is submitted.
function onSubmit(e) {
    var form = FormApp.getActiveForm(); // Get the form object
    var allResponses = form.getResponses(); // Get all of the form's responses
    var latestResponse = allResponses[allResponses.length - 1]; // Get the latest response submitted to the form
    var response = latestResponse.getItemResponses(); // Get an array containing all the responses to each question
    var items = []; // Current items array to use in embed
    var currentEmbedCharacterNum = 0 // Current number characters being used in the current embed
    
    // For loop to iterate through responses
    for (var i = 0; i < response.length; i++) {
        var question = response[i].getItem().getTitle(); // Get the question text
        var answer = response[i].getResponse(); // Get the answer text
        
        // If the answer is over a certain number of characters, break it into multiple parts.
        try {
            var parts = answer.match(/[\s\S]{1,1024}/g) || [];
        }
        catch (e) {
            var parts = answer;
        }
        
        // In this script the user's name is used in post name and to get the name, the value of a the previous question position has to be entered from the targetted question position.
        // i.e If we ask for user's name in 2nd question enter 1 where it says response[1], just chnage the number. Basically, "Position of the question - 1".
        name = response[1].getResponse().toString();
 
        // If the answer text is blank, skip this iteration.
        if (answer == "") {
            continue;
        }
        
        if (question.length > 256) {
            question = question.substring(0, 220) + "...";
        }
        
        // For loop to iterate through the parts of an answer
        for (var j = 0; j < parts.length; j++) {
            currentEmbedCharacterNum += parts[j].length + question.length; // Add the number of characters in a part to the total character count of this embed
            
            // If the total character count with this part included pushes the total over 5000 (Discord Embeds have a character limit)
            if (currentEmbedCharacterNum >= 5000) {
                sendEmbed(items); // Send away an embed with the current items data
                Utilities.sleep(60) // Wait a second so Discord doesn't get overwhelmed with requests
                currentEmbedCharacterNum = 0; // Reset the character count and items array
                items = [];
            }
            
            // If there are multiple parts to an answer, add a (cont.) to the names.
            if (j == 0) {
                items.push({
                    "name": question,
                    "value": "```• " + parts[j] + "```",
                    "inline": false
                });
            }
            else {
                items[items.length - 1].value += "```\n• " + parts[j] + "```";
            }
        }
    }
    
    // Send an embed to the webhook.
    sendEmbed(items);
    console.log("Applicant Name: " + name);
};
 
 
// Function to send an embed to the webhook url.
function sendEmbed(items) {
    var decimalColor = parseInt(embedColor.replace(/^#/, ''), 16); // Convert the color from hexadecimal to decimal
    let payload = {
        'username': webhookUsername,
        "content": messageContent,
        "embeds": [{
            "color": decimalColor,
            "author": {
                "name": authorName,
                "url": authorNameURL,
                "icon_url": authorIconURL,
            },
            "title": embedTitle,
            "url": embedTitleURL,
            "description": embedDescription,
            "fields": items,
            "thumbnail": {
                "url": thumbnailURL,
            },
            "image": {
                "url": imageURL,
            },
            "footer": {
                "text": footerText,
                "icon_url": footerIconURL,
            },
        }]
    }
    
    if (!thread_id) {
        payload.thread_name = name + postTitle;
    }
    
    // Package the embed options into a variable
    var options = {
        "method": "post",
        "headers": {
            "Content-Type": "application/json",
        },
        "payload": JSON.stringify(payload)
    };
    
    // Post the data to the webhook.
    let resp = UrlFetchApp.fetch(`${WEBHOOK_URL}${thread_id ? `&thread_id=${thread_id}` : ''}`, options).getContentText();
    thread_id = JSON.parse(resp).channel_id
    console.log(thread_id);
}

Step 4 - Create a Webhook

Create a new webhook on a Forum channel in which you want the receive the forum submission.

Create a Webhook


Step 5 - Add your Webhook URL to the Script

Add your Webhook URL to the Script

Note

You only have to replace the word webhook_url with your actual Webhook URL before the ?wait-=true


Step 6 - Save your Script

Save your Script


Step 7 - Add a trigger

Add a trigger to automate the form submission sending to your discord channel.

Add a trigger


Step 8 - Customize the trigger

After you have created a trigger you will see an popup with options to customize the trigger you just created.

Copy the options shown on the below image and save your trigger.

Customize the trigger


Step 9 - Submit your Google Form

Now everything is fully setup, fill out your google form and submit it to test if you are receiving the submission on your discord forum channel.

Submit your Google Form


Step 10 - Response Customization

You can edit how the responses looks like when you receive it on your forum channel, to do this you have to edit the values on the scripit.

I've shown which value you need to change for each element of the message that you receive in your Discord channel.

Response Customization

Note

If you want to change the color of the embed then you have to change the value which is on the right side of the = on Var embedColor = "23dde3"


Credits & Licences

I found the guide and JavaScript code to send Google Form submissions to Discord from Mourya Abhay Amarjeet on GitHub.

The project is licensed under the MIT License. You can find the links to Abhay's GitHub repository where I obtained the code and guides, as well as the license for the project below.

Abhay, thank you for writing the code and providing an easy to follow readme file for this project. Without your efforts, I would not have been able to create this guide.


Video Tutorial

If any step didn't make sense or you got stuck, you can watch a tutorial video by clicking here

Support

If you need any help then feel free to join our community server