Skip to content

Conversation

@NwE0kmCE
Copy link
Collaborator

Updates examples and instructions to discord.js v14

Copy link
Collaborator

@supercrafter100 supercrafter100 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Here are some of my thoughts. You might want to consider switching the imports to es6 ones in the future as they're becoming pretty standard now. Though it might cause some confusion amongst newcomers to the nodejs world.

}

// Construct and prepare an insance of the REST module
const rest = new REST().setToken(token);
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

token isn’t defined here from what I can see?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Updated!

$ node index.js
```
```javascript
const dotenv = require("dotenv");
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

you only required dotenv, never called dotenv.config() before reading the process.env.TOKEN variable

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

consolidated everything into one README

const { REST } = require('@discordjs/rest');
const { Routes } = require('discord-api-types/v9');
const { REST, Routes } = require("discord.js");
require("dotenv").config();
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

To keep consistent with the other code, wouldn't something like the following:

const dotenv = require('dotenv');
dotenv.config();

make more sense here?

Comment on lines 26 to 27
"discord.js": "^14.13.0",
"dotenv": "^16.3.1"
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

These would be regular dependencies though? Not dev dependencies?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

fixed!

...with...

```javascript
require("dotenv").config();
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As mentioned earlier, should we replace this with the same code from the earlier parts to keep consistent across files?

}

// Construct and prepare an insance of the REST module
const rest = new REST().setToken(process.env.CLIENTSECRET);
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

shouldn't this be process.env.TOKEN?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

fixed!


// Setup dotenv and tell it to look for `.env` in the same folder as our main file
const dotenv = require("dotenv");
dotenv.config({ path: "./.env" });
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is the path option necessary here?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

removed this exmaple for now

client.on(Events.InteractionCreate, async (interaction) => {
// Ignore interaction if it isn't a slash command
if (!interaction.isChatInputCommand()) return;
console.log(interaction.client.commands);
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same comments here as earlier about the console.logs (same applies to line 84 here)

Comment on lines 14 to 16
"devDependencies": {
"discord.js": "^14.13.0",
"dotenv": "^16.3.1"
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Starting to become repetitive 😅 same as earlier

package.json Outdated
Comment on lines 2 to 5
"devDependencies": {
"discord.js": "^14.13.0",
"dotenv": "^16.3.1"
}
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

And finally here the concern about the dev dependencies too

@shiffman
Copy link
Member

shiffman commented Oct 5, 2023

I have fixed and updated a bunch of things, I removed the second example, I will likely add more but for now just the "hello world" example with two commands! Thank you for all of the work @klinegareth and for the feedback @supercrafter100!

@shiffman shiffman merged commit 9fe20ce into main Oct 5, 2023
},
};
// Importing modules using ES6 syntax
import fetch from 'node-fetch';
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I totally forgot to mention but fetch is now natively supported in node. There isn't a need to actually install the package anymore. Since v18.18.0 it is implemented, see https://nodejs.org/dist/latest-v18.x/docs/api/globals.html for detailed information. This removes the need for this dependency.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants