MiraiForum

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

    【小白求教】如何在群成员触发命令时向群内发送一张本地图片?

    开发交流
    4
    5
    142
    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.
    • N
      N70_ last edited by N70_

      rt,我使用上传本地图片为Image的方法发送图片,但在uploadAsImage时不知道该如何调用要发送的Contact。
      顺便求问 一下大佬们,可否有相关的插件代码适合于帮助理解命令触发时的Contact、Event、CommandSender、User、Message这些东西的工作原理、工作方式?对如何使用它们不甚理解……经常在需要的时候不会调用

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

        善于翻相关源码定义

        public interface CommandSender : CoroutineScope, Permittee {
            /**
             * 与这个 [CommandSender] 相关的 [Contact].
             *
             * - 当一个群员执行指令时, [subject] 为所在 [群][Group]
             * - 当通过控制台执行时为 `null`.
             */
            public val subject: Contact?
        }
        
        N 1 Reply Last reply Reply Quote 0
        • N
          N70_ @Karlatemp last edited by

          @Karlatemp 谢谢您,但是还是有个问题
          我把sender.subject写到uploadAsImage时,显示类型不匹配,它需要一个contact,但是sender.subject返回的是Contact?
          感觉还是自己没整明白其中一些原理性的东西……

          I H 2 Replies Last reply Reply Quote 0
          • I
            ISevenVEN @N70_ last edited by ISevenVEN

            @N70_ 先感谢某位大佬对我的指点
            uploadImage(event.getGroup(),ExternalResource.create(fis));
            可以把,第一个参数理解为java中传递this,你这是在群里发 所以是getGroup,如果是个人的话 event.getSender
            然后推荐链式调用
            Image img = event.getGroup().uploadImage(ExternalResource.create(fis));

            1 Reply Last reply Reply Quote 1
            • H
              hundun000 ⭐2021⭐ @N70_ last edited by hundun000

              @N70_ Contact?涉及null-safety相关特性

              我一般会对控制台执行时也给个text反馈:

              if (commandSender.subject != null) {
                var image = externalResource.uploadAsImage(commandSender.subject!!)
                // send
              } else {
                var plainText = PlainText("已收到指令,但该接收者暂不支持图片")
                // send
              }
              
              1 Reply Last reply Reply Quote 1
              • 1 / 1
              • First post
                Last post
              Powered by Mamoe Technologies & NodeBB | 友情链接 | 服务监控 | Contact