Cannot set properties of undefined (setting 'commands')

My code:
const fs = require('fs');
const { Collection } = require('discord.js');

function registerCommands(client) {
const commands = [];

client.commands = new Collection();
}

module.exports = register();
const fs = require('fs');
const { Collection } = require('discord.js');

function registerCommands(client) {
const commands = [];

client.commands = new Collection();
}

module.exports = register();
const { Client } = require('discord.js');

const client = new Client({
intents: [
'Guilds',
'GuildMessages',
'MessageContent'
]
});

require('./functions/registerCommands.js').register(client);
const { Client } = require('discord.js');

const client = new Client({
intents: [
'Guilds',
'GuildMessages',
'MessageContent'
]
});

require('./functions/registerCommands.js').register(client);
Error:
client.commands = new Collection();
^

TypeError: Cannot set properties of undefined (setting 'commands')
client.commands = new Collection();
^

TypeError: Cannot set properties of undefined (setting 'commands')
3 Replies
Unknown User
Unknown User2y ago
Message Not Public
Sign In & Join Server To View
duck
duck2y ago
module.exports = register();
you're calling register, so you're exporting what register returns (with the error originating from calling register with no params) I imagine you'd also want it in an object or otherwise using exports.register
Skuffies
SkuffiesOP2y ago
Thank you, this solved the issue.
Want results from more Discord servers?
Add your server