Github Com
Github Com
No one assigned
Hello. I still don't understand how to use MessageMedia.fromUrl() . Can anyone give me an example?
Labels
None yet
andrii-bohdan commented on Feb 3, 2022
Projects
Hi, simple example
None yet
let url = "https://wwebjs.dev/logo.png";
const media = await MessageMedia.fromUrl(url);
Milestone
media.mimetype = "image/png";
No milestone
media.filename = "CustomImageName.png";
client.sendMessage("xxxxxxxxx@c.us", media, {caption: "Image"});
Development
6 1 1 No branches or pull requests
6 participants
I see... so do we still have to specify a filename? Can I just use a URL to create a media directly?
I see... so do we still have to specify a filename? Can I just use a URL to create a media directly?
(async () => {
let url ="some url"
const media = await MessageMedia.fromUrl(url);
client.sendMessage("xxxxxxxx@c.us", media, {caption: "some caption"}) ;
})();
Update
If you calling media from client.on("ready" () => {}); try to add async inside this function
Example:
Isso ocorre porque essa operação deve ser assíncrona. A solução pode ser Colocar seu código dentro de uma função anônima
(async () => { let url ="some url" const media = await MessageMedia.fromUrl(url); client.sendMessage("xxxxxxxx@c.us",
media, {caption: "some caption"}) ; })();
Update Se você estiver chamando a mídia de **client.on("ready" () => {}); ** tente adicionar async dentro desta função Exemplo:
client.on("message", async(msg) => { //now you have available await operation const media = await MessageMedia.fromUrl(url);
})
Hello, i have the solution, use the await method and don't use "new MessageMedia", see the example:
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Terms Privacy Security Status Docs Contact Manage cookies Do not share my personal information