discordjs / guide

The official guide for discord.js, created and maintained by core members of its community.
https://discordjs.guide
MIT License
1.57k stars 2.31k forks source link

client.commands doesn't exist apparently. #417

Closed 007-Tommy closed 4 years ago

007-Tommy commented 4 years ago

Part of the guide or code sample the question is about https://github.com/discordjs/guide/tree/master/guide/command-handling

Question How do i get it to recognise client.commands

almostSouji commented 4 years ago

The guide is sequential, it's essential you read and follow it carefully and precisely from the beginning (of at least the section you want to apply).

client.commands is set to be an empty collection in the first difference code block of the section Dynamically reading command files.

+ const fs = require('fs');
const Discord = require('discord.js');
const { prefix, token } = require('./config.json');

const client = new Discord.Client();
+ client.commands = new Discord.Collection();

This is the foundation needed to be able to set and read commands from this collection further down.

If you are stuck at some confusing behavior you can also take a peek at the Resulting code where applicable.