MiraiForum

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

    怎么发送本地图片

    开发交流
    2
    2
    546
    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.
    • P
      PANGLING998 last edited by

      Image image = group.uploadImage(ExternalResource.create(new File("src/main/resources/static/hello.jpg")));
      group.sendMessage(image);
      group.sendMessage("你好吖 !");
      //控制台显示:
      //2021-12-12 01:05:39 V/Bot xxxx: Group() <- [mirai:image:{B08D0D52-BF01-21B3-D823-8099FA71EB42}.jpg]
      //2021-12-12 01:05:39 V/Bot xxxx: Group() <- 你好吖 !
      

      这样写有什么问题吗?文字发送出去了,为什么图片发送不出去

      1 Reply Last reply Reply Quote 0
      • Orisland
        Orisland 摸鱼 last edited by Orisland

        参考:此例为一次性图片,即发送后自动关闭无需close。
        需要传入sender。
        以下代码传入了CommandSenderOnMessage sender。

        Image image = ExternalResource.uploadAsImage(ExternalResource.createAutoCloseable(ExternalResource.create(new File("src/main/resources/static/hello.jpg")), sender.getSubject())
        

        你可以把这么一拖东西封装到一个小工具里,方便你的后续图片上传调用,就像这样。

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