Step 1: Create Your Google Form
Click the three dots at the top right of the form and click "Script editor"
You will see the code in the picture on the right. Delete it and move on.
Step 4: Copy any paste the below code into the script.
const webhooks = [ "" ];
/* Optional section */
const title = ""; /* Add a custom title. */
const avatarImage = ""; /* Add a logo */
const shortDescription = ""; /* A description */
const colour = "#FF0000"; /* A custom colour? Example: #78A8C6 */
const mention = ""; /*Mention yourself or a role - it should look like <@!7890975289098612689> or <@&7890975289098612689> */
/* End of optional section */
const form = FormApp.getActiveForm();
const allResponses = form.getResponses();
const latestResponse = allResponses[ allResponses.length - 1 ];
const response = latestResponse.getItemResponses();
var items = [];
if ( !webhooks ) throw "Error: No Webhook";
function embedText( e ) {
for ( var i = 0; i < response.length; i++ ) {
const question = response[ i ].getItem().getTitle();
const answer = response[ i ].getResponse();
if ( answer == "" ) continue;
items.push( { "name": question, "value": answer } );
function data( item ) { return [ `**${ item.name }**`,`${ item.value }` ].join( "\n" ); }
}
try {
if ( avatarImage !== null ) {
const embedSetup = { "method": "post", "headers": { "Content-Type": "application/json" }, muteHttpExceptions: true, "payload": JSON.stringify( { "content": ( mention ) ? `${ mention }` : " ", "embeds": [ { "title": ( title ) ? title : form.getTitle(), "thumbnail": { "url": encodeURI( avatarImage ) }, "color": ( colour ) ? parseInt(colour.substr(1), 16) : Math.floor( Math.random() * 16777215 ), "description": ( shortDescription ) ? `${ shortDescription }\n\n${ items.map( data ).join( '\n\n' ) }` : items.map( data ).join( '\n\n' ), "timestamp": new Date().toISOString(), } ] } ) };
for ( var i = 0; i < webhooks.length; i++ ) { UrlFetchApp.fetch( webhooks[ i ], embedSetup ); }
return form.deleteResponse( latestResponse.getId() );
} else {
const embedSetup = { "method": "post", "headers": { "Content-Type": "application/json" }, muteHttpExceptions: true, "payload": JSON.stringify( { "content": ( mention ) ? `${ mention }` : " ", "embeds": [ { "title": ( title ) ? title : form.getTitle(), "color": ( colour ) ? parseInt(colour.substr(1), 16) : Math.floor( Math.random() * 16777215 ), "description": ( shortDescription ) ? `${ shortDescription }\n\n${ items.map( data ).join( '\n\n' ) }` : items.map( data ).join( '\n\n' ), "timestamp": new Date().toISOString(), } ] } ) };
for ( var i = 0; i < webhooks.length; i++ ) { UrlFetchApp.fetch( webhooks[ i ], embedSetup ); }
return form.deleteResponse( latestResponse.getId() );
}
} catch(error) {
return Logger.log(error);
}
}
Step 5: Copy your webhook's url and paste it in the webhook section between the quotation marks. You can also change things like embed title, embed color, and roles/members to be mentioned. (Note: Mention User: <@userid> Mention Role: <@&roleid>
Click the Save Button
Click the timer icon
Step 8: Click the "New Trigger" button and match these parameters.
Step 9: Click Save and submit a form to test your bot.
You now have a working Discord webhook for Google Forms!