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 toolkit6mo 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
Mark6mo 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 goblinOP6mo ago
[email protected] i used a template i found on replit so that might be why it looks v12
Mark
Mark6mo 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 goblinOP6mo ago
are you talking about this
No description
d.js docs
d.js docs6mo ago
:guide: Getting Started: Introduction read more
jakub
jakub6mo 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