Skip to content

Video Correction Notes

Dipam Sen edited this page Oct 17, 2023 · 5 revisions

Welcome to the Discord-Bot-Examples wiki!

Episode 1 (introduction to NodeJS)

  • 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.

Episode 2 (Creating a bot account and adding it to your server)

  • 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.

Episode 3 (Starting out with discord.js)

  • If you want to actually show the connection steps the discord client does, you can make it log out all the debug events in the console. Using something like client.on('debug', console.log). See my attached image for what that would look like.
  • To quickly write console.log, you can just type clg in visual studio code and type enter, it will automatically write console.log and put your mouse in between the ().
  • I'd definitely recommend explaining the whole GatewayIntentbits part in more depth as it's such a misunderstood topic! If you need further explanation on how it all works, why it's called that way, etc. Let me know! I'll gladly explain it in detail 😉
  • You used a string for interactionCreate instead of the Events enum (and this actually backfired later in the video as you misspelled it 😂!). This was addressed in the final example on the repository so I assume you'll copy that one instead in the future

screenshot of debug output from discord.js

Ep 3 - About import and export syntax in ES Modules

(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

Technical detail: export expects a declaration (const, function, etc) which must have a name (so that it can be imported with that name), whereas export default expects a JS expression - any value, to be exported. This means you cannot do something like export default const answer = 42.

Clone this wiki locally