I tried to code a bot with the new discord.js version but when I try to log in, it's prompting me this error
/home/max/Schreibtisch/Discord Bots/Perplex/node_modules/discord.js/src/util/Util.js:279
if (!Object.hasOwn(given, key) || given[key] === undefined) {
^
TypeError: Object.hasOwn is not a function
at mergeDefault (/home/max/Schreibtisch/Discord Bots/Perplex/node_modules/discord.js/src/util/Util.js:279:17)
at new BaseClient (/home/max/Schreibtisch/Discord Bots/Perplex/node_modules/discord.js/src/client/BaseClient.js:25:20)
at new Client (/home/max/Schreibtisch/Discord Bots/Perplex/node_modules/discord.js/src/client/Client.js:43:5)
at Object.<anonymous> (/home/max/Schreibtisch/Discord Bots/Perplex/src/bot.js:26:16)
at Module._compile (node:internal/modules/cjs/loader:1108:14)
at Object.Module._extensions..js (node:internal/modules/cjs/loader:1137:10)
at Module.load (node:internal/modules/cjs/loader:988:32)
at Function.Module._load (node:internal/modules/cjs/loader:828:14)
at Function.executeUserEntryPoint [as runMain] (node:internal/modules/run_main:76:12)
at node:internal/main/run_main_module:17:47
this is my bot code
const { Client, GatewayIntentBits } = require('discord.js');
const client = new Client({ intents: [GatewayIntentBits.Guilds] });
client.on('ready', () => {
console.log(`Logged in as ${client.user.tag}!`);
});
client.on('interactionCreate', async (interaction) => {
if (!interaction.isChatInputCommand()) return;
if (interaction.commandName === 'ping') {
await interaction.reply('Pong!');
}
});
client.login('token');
I don't think there is an error in this code snippet. If this is your src/bot.js file then it seems okay.
However, the error says "Object.hasOwn is not a function" and Object.hasOwn is only available since node.js v16.9.0.
Discord.js v14 requires node.js 16.9 or higher, so make sure you're up to date. To check your node version, use node -v in your terminal or command prompt, and if it's older than this, update it!
For more breaking changes, you can check out this answer: Discord.js v13 code breaks when upgrading to v14
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With