Uncaught Promise Error: TypeError: Cannot read property 'prototype' of undefined


#1

Hello
I tried to change my bot from komada to klasa, but this error apears. What is happening?
Here is my project link: https://glitch.com/edit/#!/warlock-gaming-bot
Please help me!


#3

I suggest removing the link to your project,as your token is in there, and someone can Hijack your bot and do very bad things!


#4

Hey @TheBigerGamer, here’s what I think is going on.

Klasa is, unfortnately, not a drop-in replacement for Komada, so your Komada objects need to be modified to work properly with Klasa. Here’s one example:

Komada Command objects are expected to export a run function and optional conf and help properties. This is the model that your commands are following, for example https://glitch.com/edit/#!/warlock-gaming-bot?path=commands/Fun/Interactions/8ball.js.

Klasa Command objects, on the other hand, are constructed differently. They’re expected to export a class that extends the Klasa base object and that includes its configuration in the constructor function and also to have a run function and an optional init function.

So in short, you’ll need to change up all your commands to use the new format of the Klasa objects as shown in the Klasa documents. This explains why your logs are filled with messages like this

[2019-02-27 18:16:34] TypeError: Exported Structure Not A Class
[2019-02-27 18:16:34] /app/commands/Fun/Interactions/8ball.js

Basically that’s Klasa saying “you told me to load something called 8ball but when I tried to do that it wasn’t a class like I expected”.

That also, at least on the surface, might explain the other error; Klasa was trying to use a property of something that it couldn’t load (and which is, therefore, “undefined”).

The Klasa GitHub repo has sample implementation of some of the same commands you’re using. For example, this is their implementation of the 8ball command you have. Those might help you make the switch.

I’ll also second what @Callum-OKane said; because your project is public (which is important for not-Glitch-staff to be able to help) and because your token is in a public file, your bot’s token’s been seen by anyone who’s looked at your project and you should revoke it ASAP and get another one. If you want to keep your project public so you can continue to rely on the community for help, you can put the new token in your .env file, maybe in a variable called TOKEN. Then in your bot code, after you require() the other data in your config file, you could use config.token = process.env.TOKEN;. This will mean that folks can see (but not edit) the majority of your bot’s code, and offer specific suggestions to problems you run into, while not being able to see your secrets in your .env file (only a few Glitch staff members and people you specifically invite using the Share options will be able to read that).

Hope this helps, and happy Glitching!


Komada to klasa update
#5

Thanks, it helped. But now it is showing me this:


Now what’s going on?

EDIT: Now it shows me this:


#6

That’s exactly the same issue for the commands listed in the error message, namely that https://glitch.com/edit/#!/warlock-gaming-bot?path=commands/General/Calculator/multiply.js and https://glitch.com/edit/#!/warlock-gaming-bot?path=commands/General/Calculator/subtract.js will need the same treatment. In fact, everything in your commands folder will need to be updated.


#7

Reminder: Make sure to remove the projects link from the topic at the top, because your bots token is stored there, another solution, would to put the bot’s token into ENV, and then in your project, use process.env.TOKEN to fetch it again! Anything in the env, is not visible to the public!


#8

Oh. Wow. That will be a lot of work… But how shall I remake them?


#9

Hey there, yes, I suspect it will be quite a bit of work. Perhaps some of the other commands you’re using already have samples in the Klasa repo and you can just copy them over, but other ones you’ll have to rewrite to the new format, and hopefully the examples of the changes between the Komada and Klasa versions of the same command can help things along.

If you’re asking for advice about how to approach it, if I were doing the work I’d probably do a couple of things:

  1. I’d move the broken commands to a temp folder where they’re not getting loaded and work on migrating them one at a time, only moving it back into the loaded command list when it’s working. That way your bot could continue working while you add functionality back to it.
  2. I might also put the bot’s code into a public GitHub repo or something like that, and enlist the help of other developers who have an interest in helping with the bot. Friends in a Discord server might be a good place to start. If folks are interested then you don’t need to make all of the changes yourself!

Good luck!


#10

Thanks. I’ll try to do it.