Skip to content

Instantly share code, notes, and snippets.

@adiologydev
Last active July 17, 2020 20:13
Show Gist options
  • Save adiologydev/1f3082ff09290205bf067b69a5a2af22 to your computer and use it in GitHub Desktop.
Save adiologydev/1f3082ff09290205bf067b69a5a2af22 to your computer and use it in GitHub Desktop.
discord.js to @klasa/core | Migration Guide

Recently Klasa (discord.js bot framework) has migrated to it's own Discord API wrapper @klasa/core instead of using the generic discord.js.

Why another Discord API Wrapper?

  • Creation of @klasa/core gives full customizability to it's core that discord.js failed to offer.
  • @klasa/core has High-Level API with Low-Level Performance.
  • Implements Discord API more directly unlike discord.js.
  • Allows implementation of Custom API Interactions using Actions.
  • Sends exactly what it's asked to by your code to the Discord API without any transformations.
  • Does not contain over a thousand overloads unlike discord.js. It's completely written in TypeScript.
  • Performance improvements in comparison to discord.js.

Channel Names in Dirigeants Discord

  • #klasa-core is the Discord API Wrapper that replaces discord.js.
  • #klasa-next is the Klasa version that utilizes @klasa/core instead of discord.js
  • #klasa-stable is the older and outdated Klasa's version that uses discord.js.

Official Documentation

Changes in discord.js and @klasa/core (API Wrapper)

  • <Client>.login(TOKEN) is now <Client>.connect() prior to which you will have to define your token to your Client by doing <Client>.token = "YOUR TOKEN". This offers more safety as it stores the token in a Private Field and does not store it where it can be accessed by the end user.
  • Colors can now only be used as decimal (i.e. 3093151) instead of hexadecimal (i.e. #2F329F). You can also use 0x<HEXADECIMAL> (i.e. 0x2F329F).
  • More Conventional OOP design, for example it's now guild.bans.add(<ID>) and member.ban() and not guild.ban(<ID>).
  • Async Iterators have been added:
for await (const [message] of channel.messages.iterate({ idle: 30000 })) {
  // Do something with message until there is no message for 30 seconds
}
for await (const [reaction, user] of message.reactions.iterate({ limit: 5 })) {
  // Do something with the first 5 reactions/users for the given message
}
  • Introducing Builders for Messages, WebHooks, Presence, etc. This means you won't be able to just do <channel>.send() like you used to, now you'll have to send a Message that was created using the MessageBuilder and thus the same for things of similar nature. Here's an example of User Presence:
this.client.user.presence.modify(pb => pb // pb an instance of PresenceBuilder
  .setGame(gb => gb // gb an instance of PresenceGameBuilder
    .setType(ActivityTypes.Listening)
    .setName('@BotMention help')
));

Changes to Klasa after @klasa/core (Bot Framework)

  • klasa remains almost similar to it's previous versions except...

Contributors To This Guide

raplayer dope channel#0001, kyra#0001, enkiel#8897, doge#1234, StarlitePyro#2691, AoDude#8676

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