Unexpected parentheses - idkbot


Hello, I am using Glitch to make a Discord bot with Eris. I have the following code in one portion of it:

bot.registerCommand('giphy', (msg, args) => {
  if(args.length === 0) {
    return "Invalid input";
  var textcontent = args.join(" ");
  request = new XMLHttpRequest;
  request.open('GET', 'http://api.giphy.com/v1/gifs/translate?api_key=' + process.env.GIPHY_TOKEN + '&s=' + textcontent, true);    
  request.onload = function() {
  if (request.status >= 200 && request.status < 400){
    data = JSON.parse(request.responseText).data.embed_url;
    return data;
  } else {
  	console.log('reached giphy, but API returned an error');
    return "error";
}, {
    description: "Get a gif from GIPHY with keywords",
    fullDescription: "This will use GIPHY translate to change keywords to a gif.",
    usage: "<keywords>"
}); // on this line, i get an unexpected token ) error

I looked the code over with a friend and neither of us can find any issues. Any thoughts?

EDIT: Exact error:



SyntaxError: Unexpected token )

   at createScript (vm.js:80:10)

   at Object.runInThisContext (vm.js:139:10)

   at Module._compile (module.js:616:28)

   at Object.Module._extensions..js (module.js:663:10)

   at Module.load (module.js:565:32)

   at tryModuleLoad (module.js:505:12)

   at Function.Module._load (module.js:497:3)

   at Function.Module.runMain (module.js:693:10)

   at startup (bootstrap_node.js:188:16)

   at bootstrap_node.js:609


okay never mind! It turns out that I forgot to close the request.onload function :roll_eyes:


Glad you got it sorted! It’s easily done.


Javascript can be pretty unforgiving about stuff like that! I like to use LINTers in my projects to help me spot bugs like these.

The Glitch editor has a basic one, but it’s not customizable yet. If you’re interested, check out https://glitch.com/~eslint-example for an example of how to get eslint up and running with your own config rules.

If something like that were running, it would help catch syntax errors like these by reporting them as errors in your activity log.

Happy coding :slight_smile: