-
Notifications
You must be signed in to change notification settings - Fork 7
Video Correction Notes
Welcome to the Discord-Bot-Examples wiki!
- Windows comes with a native terminal as well (command prompt) but has pretty much no Unix commands. There's a little cheat sheet that maps unix -> windows but it's not really ideal. An alternative is using the git bash (which automatically adds the unix commands) but is only available when you have installed git or just using wsl which essentially runs linux on your windows machine. There are also tools like Cygwin that create the commands on windows. See https://www.cygwin.com/ for more information. I think an important thing to know is that probably over 70% of the users following your tutorial series run windows so none of those unix commands will function for the majority of people which is pretty unfortunate.
- The official nvm doesn't work on windows as it's natively written for unix based systems. There is a maintained alternative that can be found here which I've been using on my windows computer fine for some time now. Though it can be a bit of a pain sometimes (because windows is just the most confusing thing ever)
- Note that you can do npm init -y to automatically answer "yes" to every question it asks. That way it doesn't keep asking the questions but just uses the default for everything.
- At 2:16 the contrast on the little popup is just very odd (and makes it a little unclear). I assume this is a result of that visual glitching. In general the resolution of the computer footage seems to be way lower compared to the camera. I personally don't really find it an issue it's still manageable but it is a bit odd compared to the other videos 😂
- You might want to explain what the bot permissions does on the developer portal. When a discord bot joins a Discord server, a role is automatically created for that bot that is equivalent to the name of the bot which cannot be modified by anyone. The permissions that are applied to that role will be the equivalent of the permissions you chose on the developer portal.
(dipamsen)
You are demonstrating three different types of import statements in a file, so might be worth explaining what they are: ( MDN Ref )
import { Client, Events, GatewayIntentBits } from 'discord.js';
import dotenv from 'dotenv'; // though this is changed in the final example to a named import
import * as choochoo from './commands/choochoo.js';
Firstly, import { a, b } from "library"
is not Destructuring. You can call it that, everyone calls it that because the earlier syntax const {a, b} = require("library")
is in fact destructuring. But the import statement is just a new syntax for Named Imports - importing multiple things from a module. These "things" correspond to Named Exports, which is what you are doing in command files; export const fooBar = 42
=> import { fooBar } from "file"
.
// library.js
export const data = {
name: "Coding Train"
}
export function add(x, y) {
return x + y;
}
// index.js
import { data, add } from "library.js";
console.log(data);
console.log(add(3, 4));
While having named exports, it is possible to namespace all the exports under a single name by using import * as name from "file"
, which will import all named exports as properties under a single object, name
. (Namespaced import)
// library.js
export const data = {
name: "Coding Train"
}
export function add(x, y) {
return x + y;
}
// index.js
import * as myLib from "library.js";
console.log(myLib.data);
console.log(myLib.add(3, 4));
Finally, the import name from "file"
(though you wont need this) is default import, which will import the default export (duh), which is exported as export default myValue
. Here the name of the import doesnt matter.
// library.js
let answer = 42
export default answer // only one thing can be exported as default
// index.js
import library from "library.js" // name of import can be anything, usually name of library/file