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

Code samples outdated/missing from guide documentation #1432

Closed Reality-Cache closed 1 year ago

Reality-Cache commented 1 year ago

Describe the bug

Trying to follow the code samples on the discordjs.guide website is semi-simple, but it's very easy to lose track of where something should go. So after checking the repo you'll notice that many things are in different places or completely missing from the repo. And this isn't super complicated stuff its a lot of stuff in the first few chapters, especially the command handler and event handler parts. And in the event handler repo there is no mention of anything command handler related, so there's no way to just copy the code (not trying to steal code but after an hour of trying to get something to work copying the page is what I'm going to do) Hope this can be fixed soon! Thanks :)

To Reproduce

Go to https://discordjs.guide/creating-your-bot/command-handling.html#loading-command-files Follow until command handler > Loading command files Scroll down to second code snipped. The second code snippet is completely missing from the repo

Screenshots

No response

Device (please complete the following information)

MacBook Air Apple M2 MacOS Ventura 13.2.1

Additional notes

I'm trying to learn this in a short-ish period of time and it would be really sweet if this could be solved. Just need someone smarter than me to put the snippets in the right place :)

almostSouji commented 1 year ago

I don't know what exactly the issue is you are reporting, could you elaborate? We highlight lines in code blocks that are added or changed; accordingly,

client.commands = new Collection();

refers to the file you have built so far (with the imports on top) and the client initialization. The highlighted parts are added below.

Reality-Cache commented 1 year ago

I don't know what exactly the issue is you are reporting, could you elaborate? We highlight lines in code blocks that are added or changed; accordingly,

client.commands = new Collection();

refers to the file you have built so far (with the imports on top) and the client initialization. The highlighted parts are added below.

Yes but at the end of doing this isn't the GitHub a review of everything I've done so far? But its missing important things from the discordjs.guide

Reality-Cache commented 1 year ago

like for example where is this in the GitHub?

client.commands = new Collection();

const commandsPath = path.join(__dirname, 'commands');
const commandFiles = fs.readdirSync(commandsPath).filter(file => file.endsWith('.js'));

for (const file of commandFiles) {
    const filePath = path.join(commandsPath, file);
    const command = require(filePath);
    // Set a new item in the Collection with the key as the command name and the value as the exported module
    if ('data' in command && 'execute' in command) {
        client.commands.set(command.data.name, command);
    } else {
        console.log(`[WARNING] The command at ${filePath} is missing a required "data" or "execute" property.`);
    }
} 

shouldn't that be in the GitHub index.js?

almostSouji commented 1 year ago

I see! Yes, this seems to have been missed in (the quite large) #1281, where that check was introduced.

Reality-Cache commented 1 year ago

I see! Yes, this seems to have been missed in (the quite large) #1281, where that check was introduced.

Thanks so much, thought I was crazy for a bit. If there's anything else missing can I put it in this thread?

almostSouji commented 1 year ago

sure

monbrey commented 1 year ago

1427 is fixing similar stuff so I'll address it there if it isn't already.

Reality-Cache commented 1 year ago

My main

1427 is fixing similar stuff so I'll address it there if it isn't already.

my main question is why the event handler doesn't contain the command handler code. Is that normal? and if not will that be fixed?

monbrey commented 1 year ago

Yes, that is being "fixed" by that PR. I even say that in the description :)

I realised people were deleting the command handler (even though the page doesn't tell you to) so I'm adding it back to the samples.

Reality-Cache commented 1 year ago

Yes, that is being "fixed" by that PR. I even say that in the description :)

I realised people were deleting the command handler (even though the page doesn't tell you to) so I'm adding it back to the samples.

If you need help I did everything myself yesterday and posted it to my GitHub. It should be mostly commented so if u want to just copy-paste it feel free to.