Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

无法使用本地图片发送消息 #76

Open
feilongproject opened this issue Jun 16, 2022 · 4 comments
Open

无法使用本地图片发送消息 #76

feilongproject opened this issue Jun 16, 2022 · 4 comments

Comments

@feilongproject
Copy link

官方API文档里有说明,可以通过multipart/form-data参数里的file_image字段,直接通过文件上传的方式发送图片,请求适配

@Giftia
Copy link

Giftia commented Jun 16, 2022

附议,帖子的接口nodeSDK也该跟进一下

@1011382654
Copy link

+1

@feilongproject
Copy link
Author

目前自己写了个example

import FormData from 'form-data';////需要自己安装
import fetchfrom 'node-fetch';//需要自己安装
import fs from 'fs';
import { IMessage } from 'qq-guild-bot';

export async function sendImage(msg: IMessage, picName: string,) {

    picName = picName?.startsWith("/") ? picName : `${config.picPath.out}/${picName}`;
    log.debug(`uploading ${picName}`);

    var picData = fs.createReadStream(picName);

    var formdata = new FormData();
    formdata.append("msg_id", msg.id);
    //formdata.append("content", "123456");
    formdata.append("file_image", picData);

    await fetch(`https://api.sgroup.qq.com/channels/${msg.channel_id}/messages`, {
        method: "POST",
        headers: {
            "Content-Type": formdata.getHeaders()["content-type"],
            "Authorization": `Bot ${config.appID}.${config.token}`
        },
        body: formdata

    }).then(async res => {
        const body = await res.json();
        if (body.code)
            throw new Error(body);

    }).catch(error => {
        log.error(error);
    })

}

@NWYLZW
Copy link

NWYLZW commented Oct 26, 2022

https://github.com/satorijs/qq-guild-sdk/blob/master/packages/core/test/index.spec.ts#L48-L53

欢迎试试我的,或者尝试一下 koishi ,koishi 的 adapter 也是基于该 sdk 封装的

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants