javascript - How can i import thing in js ? (discord.js) - Stack Overflow

I got a problem with import in js for a discord bot.This is a part of my code :import * as Discord fro

I got a problem with import in js for a discord bot. This is a part of my code :

import * as Discord from "discord.js";
import * as fs from "fs";

import config from "./config.json";

const client = new Discord.Client();

But, i got an error :

import * as Discord from "discord.js";
       ^

SyntaxError: Unexpected token *
    at Module._pile (internal/modules/cjs/loader.js:722:23)
    at Object.Module._extensions..js (internal/modules/cjs/loader.js:798:10)
    at Module.load (internal/modules/cjs/loader.js:645:32)
    at Function.Module._load (internal/modules/cjs/loader.js:560:12)
    at internal/modules/esm/translators.js:100:15
    at Object.meta.done (internal/modules/esm/create_dynamic_module.js:48:9)
    at file:///C:/Users/Teo/Desktop/altv-server/resources/discord/bot/index.js:9:13
    at ModuleJob.run (internal/modules/esm/module_job.js:111:37)
    at processTicksAndRejections (internal/process/task_queues.js:89:5)
    at async Loader.import (internal/modules/esm/loader.js:131:24)

I don't know why I'm getting this error. Can someone help me to solve my issue ?

I got a problem with import in js for a discord bot. This is a part of my code :

import * as Discord from "discord.js";
import * as fs from "fs";

import config from "./config.json";

const client = new Discord.Client();

But, i got an error :

import * as Discord from "discord.js";
       ^

SyntaxError: Unexpected token *
    at Module._pile (internal/modules/cjs/loader.js:722:23)
    at Object.Module._extensions..js (internal/modules/cjs/loader.js:798:10)
    at Module.load (internal/modules/cjs/loader.js:645:32)
    at Function.Module._load (internal/modules/cjs/loader.js:560:12)
    at internal/modules/esm/translators.js:100:15
    at Object.meta.done (internal/modules/esm/create_dynamic_module.js:48:9)
    at file:///C:/Users/Teo/Desktop/altv-server/resources/discord/bot/index.js:9:13
    at ModuleJob.run (internal/modules/esm/module_job.js:111:37)
    at processTicksAndRejections (internal/process/task_queues.js:89:5)
    at async Loader.import (internal/modules/esm/loader.js:131:24)

I don't know why I'm getting this error. Can someone help me to solve my issue ?

Share Improve this question asked May 6, 2020 at 15:21 ScoffgardScoffgard 131 silver badge4 bronze badges
Add a ment  | 

3 Answers 3

Reset to default 3

According to dicord.js documentation since they released their package as a mon js package in order to load it, you should use ES5 importing style with require.

So it should be like this:

const Discord = require('discord.js');

Have you tried using the Require Library?

You can't selectively load only the pieces you need with require but with imports, you can selectively load only the pieces you need. That can save memory.

const Discord = require('discord.js/browser');

You can try:

const { Client, Events, GatewayIntentBits } = require("discord.js");

source: // https://discordjs.guide/additional-info/es6-syntax.html#template-literals

发布者:admin,转转请注明出处:http://www.yc00.com/questions/1745141384a4613448.html

相关推荐

  • javascript - How can i import thing in js ? (discord.js) - Stack Overflow

    I got a problem with import in js for a discord bot.This is a part of my code :import * as Discord fro

    1小时前
    20

发表回复

评论列表(0条)

  • 暂无评论

联系我们

400-800-8888

在线咨询: QQ交谈

邮件:admin@example.com

工作时间:周一至周五,9:30-18:30,节假日休息

关注微信