Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How To Fix "Lexical declaration cannot appear in a single-statement context"

when i make a embed and run the bot, the problem here appears cos i used a let EmbedHelp = Discord.RichEmbed this problems appears in the Terminal, please type the problem and what i need to fix :

SyntaxError: Lexical declaration cannot appear in a single-statement context
   at new Script (vm.js:79:7)
   at createScript (vm.js:251:10)
   at Object.runInThisContext (vm.js:303:10)
   at Module._compile (internal/modules/cjs/loader.js:657:28)
   at Object.Module._extensions..js (internal/modules/cjs/loader.js:700:10)
   at Module.load (internal/modules/cjs/loader.js:599:32)
   at tryModuleLoad (internal/modules/cjs/loader.js:538:12)
   at Function.Module._load (internal/modules/cjs/loader.js:530:3)
   at Function.Module.runMain (internal/modules/cjs/loader.js:742:12)
   at startup (internal/bootstrap/node.js:283:19) 

the code i use for the embed is :

client.on('message', message => {
    if (message.startsWith('$Commands'))

    let EmbedHelp = Discord.RichEmbed()
        "title": "title ~~(did you know you can have markdown here too?)~~",
        "description": "```",
        "url": "https://discordapp.com",
        "color": 192748,
        "timestamp": "Timezone - GGT 3+",
        "footer": {
            "icon_url": "https://cdn.discordapp.com/avatars/563449221701959700/8386d5fe48d71898c40244e7a5a66d58.png",
            "text": "footer text"
        },
        "thumbnail": {
            "url": "https://cdn.discordapp.com/avatars/563449221701959700/8386d5fe48d71898c40244e7a5a66d58.png"
        },
        "image": {
            "url": "https://cdn.discordapp.com/embed/avatars/0.png"
        },
        "author": {
            "name": "Galak$y#3038",
            "url": "https://discordapp.com",
            "icon_url": "https://discordapp.com/channels/564059839320555540/569179399211974666"
        },

    }
});
channel.send({EmbedHelp})


like image 247
Galaksy Avatar asked Jan 27 '23 10:01

Galaksy


1 Answers

That error is referring to the line below Discord.RichEmbed(). You have an Object property declaration without any Object in sight. Looks like you're mixing up a few things that you tried to pull from the Discord docs.

RichEmbed is intended to be chained with other helper methods. If you instead put your code into an Object (wrapping it in curly braces {}) and pass it into an send method, it should get rid of that error.

client.on('message', (message) => {
  if (message.startsWith('$Commands')) {
    message.channel.send({
      embed: {
        title: 'title ~~(did you know you can have markdown here too?)~~',
        description: '```',
        url: 'https://discordapp.com',
        color: 192748,
        timestamp: 'Timezone - GGT 3+',
        footer: {
          icon_url:
            'https://cdn.discordapp.com/avatars/563449221701959700/8386d5fe48d71898c40244e7a5a66d58.png',
          text: 'footer text',
        },
        thumbnail: {
          url: 'https://cdn.discordapp.com/avatars/563449221701959700/8386d5fe48d71898c40244e7a5a66d58.png',
        },
        image: {
          url: 'https://cdn.discordapp.com/embed/avatars/0.png',
        },
        author: {
          name: 'Galak$y#3038',
          url: 'https://discordapp.com',
          icon_url:
            'https://discordapp.com/channels/564059839320555540/569179399211974666',
        },
      },
    });
  }
});

like image 104
LMulvey Avatar answered Jan 29 '23 08:01

LMulvey