Cannot Read Properties of undefined

I'm using a starting guide for discord.js (discordjs.guide) this is the code it gave me
const { Client, Events, GatewayIntentBits, intents } = import('discord.js');
const { token } = import('./config.json');

// Create a new client instance
const client = new Client({ intents: [GatewayIntentBits.Guilds] });

// When the client is ready, run this code (only once).
// The distinction between `client: Client<boolean>` and `readyClient: Client<true>` is important for TypeScript developers.
// It makes some properties non-nullable.
client.once(Events.ClientReady, readyClient => {
console.log(`Ready! Logged in as ${readyClient.user.tag}`);
});

// Log in to Discord with your client's token
client.login(token);
const { Client, Events, GatewayIntentBits, intents } = import('discord.js');
const { token } = import('./config.json');

// Create a new client instance
const client = new Client({ intents: [GatewayIntentBits.Guilds] });

// When the client is ready, run this code (only once).
// The distinction between `client: Client<boolean>` and `readyClient: Client<true>` is important for TypeScript developers.
// It makes some properties non-nullable.
client.once(Events.ClientReady, readyClient => {
console.log(`Ready! Logged in as ${readyClient.user.tag}`);
});

// Log in to Discord with your client's token
client.login(token);
Error:
Uncaught TypeError TypeError: Cannot read properties of undefined (reading 'Guilds')
at <anonymous> (c:\Users\Kano2\Downloads\node\index.mjs:14:57)
at run (internal/modules/esm/module_job:194:25)
--- await ---
at processTicksAndRejections (internal/process/task_queues:95:5)
--- await ---
at runMainESM (internal/modules/run_main:55:21)
at executeUserEntryPoint (internal/modules/run_main:78:5)
at <anonymous> (internal/main/run_main_module:23:47)
Uncaught TypeError TypeError: Cannot read properties of undefined (reading 'Guilds')
at <anonymous> (c:\Users\Kano2\Downloads\node\index.mjs:14:57)
at run (internal/modules/esm/module_job:194:25)
--- await ---
at processTicksAndRejections (internal/process/task_queues:95:5)
--- await ---
at runMainESM (internal/modules/run_main:55:21)
at executeUserEntryPoint (internal/modules/run_main:78:5)
at <anonymous> (internal/main/run_main_module:23:47)
5 Replies
d.js toolkit
d.js toolkitβ€’12mo 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!
π™†π˜Όπ™‰π™Š
- 14.14.1 DJS version - v18.16.0 Node V
treble/luna
treble/lunaβ€’12mo ago
npm ls discord.js ah wait either user require, or import not both
π™†π˜Όπ™‰π™Š
what sorry im really new to java and djs
treble/luna
treble/lunaβ€’12mo ago
this is javascript if you're new, please learn the basics of js first, #rules 3 #resources
Want results from more Discord servers?
Add your server