4

I wanted to create a script, which would send data from the google form to the discord webhook in google apps script. But I receive the error in the first line:

import { client as _client } from 'discord.js';
const client = new _client();

Here is the error:

Syntax error: SyntaxError: Cannot use import statement outside a module line: 1 file: Code.gs
domovonok
  • 89
  • 6

2 Answers2

2

discord.js depends on Node.js. It cannot run on Google Apps Script.

If you want to contact a discord webhook, then do so directly using the UrlFetchApp API as per the External APIs guide.

Quentin
  • 914,110
  • 126
  • 1,211
  • 1,335
0

Currently, Google Apps Script does not support ES modules. Hence the typical export/import pattern cannot be used and will fail.

One way of handling this is to use rollup.js to bundle your project into one single JavaScript file.

The trick here is to make sure not to export any functions in your entry point code, e.g. index.ts, and to prevent any generation of export statement in the final bundle (see the custom rollup plugin in the rollup.config.js below).

See code: https://github.com/google/clasp/blob/master/docs/esmodules.md

See also: The ULTIMATE Guide to NPM Modules in Google Apps Script

Or even: Using npm modules inside of Apps Script

Magne
  • 16,401
  • 10
  • 68
  • 88