革兰氏JS。消息问题。sendMedia,channels.editphoto

发布于 2025-01-30 08:13:02 字数 2158 浏览 3 评论 0原文

我正在创建电报客户端来创建模板频道。我主要获得了我想要的所有功能,但是我被所有暗示上传媒体的功能所困扰:

当我使用Message.SendMedia方法时,我总是会遇到此错误:

Error: Disconnect (caused from messages.SendMedia)
at /Users/apple/Desktop/Projects/Telegram-Bots/gram-js/node_modules/telegram/extensions/MessagePacker.js:107:33
at Array.forEach (<anonymous>)
at MessagePacker.rejectAll (/Users/apple/Desktop/Projects/Telegram-Bots/gram-js/node_modules/telegram/extensions/MessagePacker.js:105:29)
at MTProtoSender._disconnect (/Users/apple/Desktop/Projects/Telegram-Bots/gram-js/node_modules/telegram/network/MTProtoSender.js:249:25)
at MTProtoSender.disconnect (/Users/apple/Desktop/Projects/Telegram-Bots/gram-js/node_modules/telegram/network/MTProtoSender.js:168:20)
at TelegramClient.disconnect (/Users/apple/Desktop/Projects/Telegram-Bots/gram-js/node_modules/telegram/client/telegramBaseClient.js:163:32)
at _updateLoop (/Users/apple/Desktop/Projects/Telegram-Bots/gram-js/node_modules/telegram/client/updates.js:177:26)

这是我执行的代码:

const sendMedia = async (channelId) => {
    const file = await client.uploadFile({
        file: new CustomFile(
            'stakazo.jpeg',
            fs.statSync(
                '/Users/apple/Desktop/Projects/Telegram-Bots/gram-js/images/xxxxx.jpeg'
            ).size,
            '/Users/apple/Desktop/Projects/Telegram-Bots/gram-js/images/xxxxxx.jpeg'
        ),
        workers: 1,
    });

    const result = await client.invoke(
        new Api.messages.SendMedia({
            peer: channelId,
            media: new Api.InputMediaUploadedPhoto({
                file: file,
                ttlSeconds: 43,
            }),
            message: 'Hello there!',
            randomId: BigInt('-4156887774564'),
            scheduleDate: 43,
        })
    );
};

i真的被困在这里。我以为我可能是图像的问题,但没有发现任何东西。

I am creating a telegram client to create templates channels. I got mainly all the functionality I wanted but I got stuck with all the functionality that implies upload media:

When I use the message.sendMedia method I always get this error:

Error: Disconnect (caused from messages.SendMedia)
at /Users/apple/Desktop/Projects/Telegram-Bots/gram-js/node_modules/telegram/extensions/MessagePacker.js:107:33
at Array.forEach (<anonymous>)
at MessagePacker.rejectAll (/Users/apple/Desktop/Projects/Telegram-Bots/gram-js/node_modules/telegram/extensions/MessagePacker.js:105:29)
at MTProtoSender._disconnect (/Users/apple/Desktop/Projects/Telegram-Bots/gram-js/node_modules/telegram/network/MTProtoSender.js:249:25)
at MTProtoSender.disconnect (/Users/apple/Desktop/Projects/Telegram-Bots/gram-js/node_modules/telegram/network/MTProtoSender.js:168:20)
at TelegramClient.disconnect (/Users/apple/Desktop/Projects/Telegram-Bots/gram-js/node_modules/telegram/client/telegramBaseClient.js:163:32)
at _updateLoop (/Users/apple/Desktop/Projects/Telegram-Bots/gram-js/node_modules/telegram/client/updates.js:177:26)

And this one is the code I am executing:

const sendMedia = async (channelId) => {
    const file = await client.uploadFile({
        file: new CustomFile(
            'stakazo.jpeg',
            fs.statSync(
                '/Users/apple/Desktop/Projects/Telegram-Bots/gram-js/images/xxxxx.jpeg'
            ).size,
            '/Users/apple/Desktop/Projects/Telegram-Bots/gram-js/images/xxxxxx.jpeg'
        ),
        workers: 1,
    });

    const result = await client.invoke(
        new Api.messages.SendMedia({
            peer: channelId,
            media: new Api.InputMediaUploadedPhoto({
                file: file,
                ttlSeconds: 43,
            }),
            message: 'Hello there!',
            randomId: BigInt('-4156887774564'),
            scheduleDate: 43,
        })
    );
};

I am really stuck here. I thought I might be a problem with the image but did not get to find out anything.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

爱的故事 2025-02-06 08:13:02

我们可以使用此代码发送文件(图像,文档等)。

await client.sendMessage("me", {
   message: "test send file", //leave it empty if don't want to send the message with the image
   file: fileName,
});

有关更多信息,请参阅本文 - &GT; < sendfile

We can use this code to send the file(image, doc etc.).

await client.sendMessage("me", {
   message: "test send file", //leave it empty if don't want to send the message with the image
   file: fileName,
});

For more information refer to this article -> https://gram.js.org/beta/classes/TelegramClient.html#sendFile

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文