MiraiForum

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

    forwardMessage的使用

    开发交流
    3
    4
    134
    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.
    • AdorableParker
      AdorableParker last edited by

      为什么我同样的构造一个forwardMessage
      在命令里面单发就能成功发送
      自动推送里面群发就会报文件过大的错误

      // 这个代码块怎么不支持kotlin语法标注
      // 自动推送的代码块
      val bot = Bot.getInstance(MySetting.BotID)
      val forwardMessage = dynamic.getMessage(bot.asFriend, bot, time)
      for (groupInfo in groupList) {
          val groupID = groupInfo["group_id"] as Int
          val group = bot.getGroup(groupID.toLong())
          if (group != null && group.botMuteRemaining <= 0) {
              runCatching {
                  group.sendMessage(forwardMessage)
              }.onFailure {
                  logger.warning { "${it.message}" }
              }
          }
      }
      
      // 构造forwardMessage的部分
      data class Dynamic(val timestamp: Long, val text: String?, val imageStream: List<InputStream>?) {
          suspend fun getMessage(subject: Contact, uORb: UserOrBot, t:String): ForwardMessage = buildForwardMessage(subject) {
              uORb says PlainText("$text")
              imageStream?.forEach {
                  uORb says it.uploadAsImage(subject)
              }
                  uORb says PlainText("发布时间:$t")
          }
      }
      
      1 Reply Last reply Reply Quote 0
      • Karlatemp
        Karlatemp last edited by

        经典有报错不给报错信息

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

          @karlatemp 因为错误被runCatching捕获了,it.message输出的内容就是发送文件过大。。
          问题已经解决了,排查出来的信息,能知道就是使用bot.asFriend作为构建的forwardMessage的发送者,然后将这个forwardMessage发送出去就会有问题

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

            https://github.com/mamoe/mirai/issues/1590

            cssxsh created this issue in mamoe/mirai

            closed ForwardMessageInternal 的长度检查 #1590

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