-
Notifications
You must be signed in to change notification settings - Fork 33
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
Comments
附议, |
+1 |
目前自己写了个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);
})
} |
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
在官方API文档里有说明,可以通过
multipart/form-data
参数里的file_image
字段,直接通过文件上传的方式发送图片,请求适配The text was updated successfully, but these errors were encountered: