Antonios Barotsis
06/23/2020, 7:27 PMval discord = require("discord.js");
val client = discord.Client()
compiles to this
var discord = require('discord.js');
var client = discord.Client();
which gives me an error because it should instead be
var discord = require('discord.js');
var client = new discord.Client();
How do I invoke ``new`` seeing as how its not a kotlin keyword?
Edit: Im not sure if this has something to do with the way I imported the package, this is the require function, I did not make any external classes
external fun require(module: String): dynamic
araqnid
06/23/2020, 7:34 PM@JsModule("discord.js")
external object Discord {
class Client {
}
}
And then the compiler will translate access to the object Discord
into require("discord.js")
(effectively)araqnid
06/23/2020, 7:34 PMDiscord.Client()
should translate into a new
operationaraqnid
06/23/2020, 7:35 PMAntonios Barotsis
06/23/2020, 7:40 PMaraqnid
06/23/2020, 7:52 PMaraqnid
06/23/2020, 7:53 PMrequire
from Kotlin unless you have an explicit need for a dynamic require, or delaying the require of the module until that moment)araqnid
06/23/2020, 7:58 PM@JsModule("discord.js")
external object Discord {
class Client { }
}
fun createDiscordClient() = Discord.Client()
got translated to:
var Discord$Client = $module$discord_js.Client;
function createDiscordClient() {
return new Discord$Client();
}
which looks to me like what you needAntonios Barotsis
06/23/2020, 8:04 PMaraqnid
06/23/2020, 8:05 PMval discord
property isn’t being used, as Discord
is an object: you can just remove that lineAntonios Barotsis
06/23/2020, 8:06 PM