MiraiForum

    • Register
    • Login
    • Search
    • Popular
    • Recent
    • Unsolved
    • Tags
    • Groups
    • 友情链接

    在插件中嵌入ktor失败?

    开发交流
    2
    6
    578
    Loading More Posts
    • Oldest to Newest
    • Newest to Oldest
    • Most Votes
    Reply
    • Reply as topic
    Log in to reply
    This topic has been deleted. Only users with topic management privileges can see it.
    • dada
      dada last edited by

      如果正常在kotlin应用main函数中使用,可以正常运行。
      但如果在mirai插件中使用,则会出现错误代码500。
      如何解决?或者,有没有好的方法在插件中开启httpserver?

      
      override fun onEnable() {
              logger.info { "Plugin loaded" }
      
              Thread{
                  embeddedServer(Netty, port = 8081) {
                      routing {
                          get("/") {
                              this@WebListener.logger.info("hello")
                              call.respondText("success")
                          }
                      }
                  }.start(wait = true)
              }.start()
          }
      
      
      1 Reply Last reply Reply Quote 0
      • Karlatemp
        Karlatemp last edited by

        请确定打包的插件携带了 ktor-server-netty 等必要依赖,你可能需要 https://github.com/project-mirai/mirai-slf4j-bridge 来开启全部日志

        dada 1 Reply Last reply Reply Quote 0
        • dada
          dada @Karlatemp last edited by

          @karlatemp 感谢指导!log已经顺利显示,这次看到了错误信息。

          2021-10-16 22:16:12 E/ktor.application: Unhandled: GET - /
          java.lang.NoSuchMethodError: 'voidio.ktor.http.ParametersBuilder.<init>(int,io.ktor.http.UrlEncodingOption, int,kotlin.jvm.internal.DefaultConstructorMarker)'
          

          似乎在被console加载的过程中没有顺利加载处理方法

          1 Reply Last reply Reply Quote 0
          • Karlatemp
            Karlatemp last edited by

            看上去像版本冲突

            1 Reply Last reply Reply Quote 0
            • Karlatemp
              Karlatemp last edited by

              尝试使用与 mirai-core-api 所使用的 ktor 版本一致的ktor版本

              dada 1 Reply Last reply Reply Quote 0
              • dada
                dada @Karlatemp last edited by

                @karlatemp 解决了,真是神奇(^▽^) 谢谢!

                1 Reply Last reply Reply Quote 0
                • 1 / 1
                • First post
                  Last post
                Powered by Mamoe Technologies & NodeBB | 友情链接 | 服务监控 | Contact