Skip to content

怎么向QQ群发送文件啊,MessageBuilder 只看见构建图片 和文字 ,没发现文件啊 #138

Answered by ForteScarlet
zhouyt168 asked this question in Q&A
Discussion options

You must be logged in to vote
@Listener
public void sample(MiraiGroupMessageEvent event) {
    // 得到 MiraiGroup,可以通过类型判断、mirai组件专属事件类型中等方式获取
    // 此处以 '监听mirai组件专属事件: 群消息事件' 为例获取
    MiraiGroup group = event.getGroup();
    // 得到 mirai 原生的 Group 对象
    Group sourceGroup = group.getOriginalContact();
    // 接下来使用的都是mirai原生API
    RemoteFiles files = sourceGroup.getFiles();
    try (ExternalResource externalResource = ExternalResource.create(new File("xx.txt"))) {
        // 上传文件到制定路径目标
        AbsoluteFile absoluteFile = files.uploadNewFile("/foo/bar/xx.txt", externalResource);
    } catch (IOException e) {
        // 处理异常
        throw new RuntimeException(e);
    }
}

Replies: 2 comments 6 replies

Comment options

You must be logged in to vote
2 replies
@zhouyt168
Comment options

@ForteScarlet
Comment options

Answer selected by zhouyt168
Comment options

You must be logged in to vote
4 replies
@zhouyt168
Comment options

@JacianZhu
Comment options

@zhouyt168
Comment options

@JacianZhu
Comment options

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
组件:mirai 与mirai组件有关的内容
3 participants