MrPowerGamerBR
08/19/2025, 5:38 PMTimestamps
object that expects two integers: A start
and end
timestamps. These timestamps are Epoch millis. The library expects integers for these timestamps: https://discord.com/developers/docs/events/gateway-events#activity-object-activity-timestamps
But that's where the issue lies: I can't figure out a way to initialize a JavaScript Integer!
• A Kotlin Int doesn't work because converting a epoch millis to a Kotlin Int causes it to overflow and go into the negatives
• A Kotlin Long doesn't work due to the way Kotlin Long works in Kotlin/JS
• A Kotlin BigInt doesn't work because the backend (in this case, Discord's RPC protocol) complains that it isn't a number
• A Kotlin String doesn't work because the backend complains that it isn't a number
The only way I found to make it work is by initializing the number via js
, but I wonder if there's a better way to do this?
discordSDK.commands.setActivity(
SetActivityRequest(
activity = Activity(
0, // Changes the top of the activity title in the profile
"PixelBloom",
"Placing pixels at ${cursor.value?.x}, ${cursor.value?.y}",
timestamps = Timestamps(
start = js("new Date().getTime()")
)
).also {
console.log("Generated Activity: ", it)
}
)
)
broadway_lamb
08/19/2025, 6:27 PMnumber
that Kotlin has.ephemient
08/19/2025, 6:50 PMephemient
08/19/2025, 6:52 PMEdoardo Luppi
08/19/2025, 7:02 PMexternal class Timestamps(
start: Double? = definedExternally,
end: Double? = definedExternally,
)
Which will then accept a Date.now()
without conversion.
Or, if you prefer using Kotlin's built-in clock
val start = Clock.System.now().toEpochMilliseconds()
timestamps = Timestamps(start = start.toDouble())
turansky
08/19/2025, 7:24 PMEpochTimeStamp
is here 😉turansky
08/19/2025, 7:29 PMMrPowerGamerBR
08/19/2025, 8:09 PMDouble
before but sure enough it worked 🙂
@JsPlainObject
external interface Timestamps {
var start: Double?
var end: Double?
}
About the EpochTimeStamp, that would require something like this, right? @turansky
fun Long.toEpochTimeStamp() = this.toDouble().unsafeCast<EpochTimeStamp>()
and then
@JsPlainObject
external interface Timestamps {
var start: EpochTimeStamp?
var end: EpochTimeStamp?
}
(this does work because EpochTimeStamp is a typealias of Int53 and Int53 is a typealias of Double, but I don't know if it is correct)turansky
08/19/2025, 11:17 PMEpochTimeStamp
right now instead of Double
.
No additional unsafeCast
required.turansky
08/20/2025, 2:59 PM