SO i am very new to using script editor on google docs, so i apologise if i sound silly.
I have a form that has around 20 items on it. Some have a simple “done” box to click others are multiple choice questions. The items that have a done box also contain jpg within the box.
What i want to do is on form submit take the information only from certain boxes ( the questions and answers) and have it sent to Discord.
I have set up a webhook to send the information to my discord server and I have a script to send all information from the form to Discord. It works fine when i have a form that has no jpgs in but when i try and use it on the form with pictures in, it does not work.
What I want is a something that allows me to select only certain questions and answers from the form.
Can someone help please.
Here is what my script currently looks like. Much of this was copied from another form I have.
`function myFunction() {
}
const webhooks = [ "DISCORD WEBHOOK" ];
/* Start of optional section */
const title = "DOC TITLE"; /* Add a nice custom title, to make the script truly yours. */
const avatarImage = ""; /* The logo of your brand or Discord server, maybe? */
const shortDescription = ""; /* A little bit of information about the response received, so you
don't forget in the future? */
const colour = "#ffa500"; /* A custom colour? Example: #78A8C6 */
const mention = "<@flinny-k>"; /*Mention yourself or a role - it should look like
``<@7890975289098612689> or <@DISCORD USERNAME> */
/* 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 "You forgot the 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 }nn${ items.map( data
).join( 'nn' ) }` : items.map( data ).join( 'nn' ), "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 }nn${ items.map( data ).join( 'nn' ) }` : items.map(
data ).join( 'nn' ), "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);
}
}
I dont really know what to try.
I would like to be able to instruct forms to take certain questions and answers from the google form and send it to my discord.
Thank you in advance`
kai flinn is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.