kordlib / kord

Idiomatic Kotlin Wrapper for The Discord API
MIT License
909 stars 80 forks source link

Setting presence crashes the bot #956

Closed MrMasrozYTLIVE closed 2 months ago

MrMasrozYTLIVE commented 2 months ago
Exception in thread "main" kotlin.UninitializedPropertyAccessException: lateinit property socket has not been initialized
    at dev.kord.gateway.DefaultGateway.sendUnsafe(DefaultGateway.kt:280)
    at dev.kord.gateway.DefaultGateway.send(DefaultGateway.kt:263)
    at dev.kord.core.cache.CachingGateway.send(CachingGateway.kt)
    at dev.kord.core.gateway.MasterGateway$DefaultImpls.sendAll(MasterGateway.kt:36)
    at dev.kord.core.gateway.DefaultMasterGateway.sendAll(DefaultMasterGateway.kt:10)

This happens if you have any event when setting presence from Kord.login {}

MrMasrozYTLIVE commented 2 months ago
kord.on<MessageCreateEvent> { // runs every time a message is created that our bot can read
            message.getChannel().createMessage("test")
        }

        kord.login {
            kord.editPresence {
                this.watching("Tsukimichi: Moonlit Fantasy")
                this.status = PresenceStatus.DoNotDisturb
            }
        }

This code is crashing, but if you either remove Kord.on (Happens with any event) or you remove Kord.editPresence then it works just fine

DRSchlaubi commented 2 months ago

You can't send gateway commands at this point, if you want to set a presence during login use the presence builder


kord.login {
  presence {
    watching("Tsukimichi: Moonlit Fantasy")
    status = PresenceStatus.DoNotDisturb
   }
}