Creating first bot and ran into problem

Ive already done nmp i and installed discord.js in the terminal (using VSC) and when i try to run my code it says cannot run import statement outside a module
import {Discord} from 'discord.js';
const client = new Discord.Client();

client.on('ready', () => {
console.log(`Logged in as ${client.user.tag}!`);
});

client.on('message', message => {
// Here is where you need to code
if(message.content == "Node.js is cool") {
message.channel.send("Yea!");
}
});

client.login("TOKEN");
import {Discord} from 'discord.js';
const client = new Discord.Client();

client.on('ready', () => {
console.log(`Logged in as ${client.user.tag}!`);
});

client.on('message', message => {
// Here is where you need to code
if(message.content == "Node.js is cool") {
message.channel.send("Yea!");
}
});

client.login("TOKEN");
i did replace token with the actual token
7 Replies
d.js toolkit
d.js toolkit3mo ago
- What's your exact discord.js npm list discord.js and node node -v version? - Not a discord.js issue? Check out #other-js-ts. - Consider reading #how-to-get-help to improve your question! - Explain what exactly your issue is. - Post the full error stack trace, not just the top part! - Show your code! - Issue solved? Press the button!
Mark
Mark3mo ago
a) this syntax is v12 at best, what version are you actually using? b) import is only available in esm and typescript, you want to use require statements
taint goblin
taint goblin3mo ago
discord.js@14.15.3 i used a template i found on replit so that might be why it looks v12
Mark
Mark3mo ago
dunno where you got this code from, but it is extremely outdated. i suggest you read the official d.js guide instead of some random resource
taint goblin
taint goblin3mo ago
are you talking about this
No description
d.js docs
d.js docs3mo ago
:guide: Getting Started: Introduction read more
jakub
jakub3mo ago
import is only available in esm and typescript, you want to use require statements
well, if they're using import, they are using ESM so ok yeah this is the point when you add type: "module" because legacy stuff
Want results from more Discord servers?
Add your server