久久久久久久av_日韩在线中文_看一级毛片视频_日本精品二区_成人深夜福利视频_武道仙尊动漫在线观看

下載文件到本地計算機發(fā)送附加到消息不和諧

download file to local computer sent attatched to message discord(下載文件到本地計算機發(fā)送附加到消息不和諧)
本文介紹了下載文件到本地計算機發(fā)送附加到消息不和諧的處理方法,對大家解決問題具有一定的參考價值,需要的朋友們下面隨著小編來一起學習吧!

問題描述

查看 Discord.js 文檔后,我可以找到問題的答案,有人知道該怎么做嗎?頁面上已有問題,但沒有答案或評論.

after looking on the Discord.js docs i can find an answer for the question, does someone know how to do it? theres already a question the page but has no answers or comments.

想象有人在聊天中發(fā)送了一張圖片,機器人有沒有辦法下載圖片或獲取圖片的網(wǎng)址?

imagine that someone on the chat sentí an image, is there a way of the bot downloading the image or get the url of the image?

謝謝!

推薦答案

對于初學者...您需要代碼才能訪問附件.

For starters... You'd need the code to access the attachment.

client.on(`message`,function(msg){
    if(msg.attachments.first()){//checks if an attachment is sent
        if(msg.attachments.first().filename === `png`){//Download only png (customize this)
            download(msg.attachments.first().url);//Function I will show later
        }
    }
});

注意:我將附件限制為 png,以便我們下載經(jīng)過驗證的圖像.否則我們可能會下載一些不良腳本和病毒.下載東西時要小心.

Note: I limited attachments to png only so we download verified images. Otherwise we might download some bad scripts and possibly viruses. Be careful when downloading stuff.

現(xiàn)在我剛剛給你的代碼調用 download 并傳入 url.
現(xiàn)在你需要 request 模塊 AND fs 模塊.

Now the code I just gave you calls download and passes in the url.
Now you will need the request module AND the fs module.

為什么?很高興你問... request 模塊訪問 url 并從網(wǎng)絡中提取數(shù)據(jù).
fs 模塊在本地/外部機器上創(chuàng)建/讀取/寫入文件...

Why? Glad you asked... The request module accesses the url and pulls it the data from the web.
The fs module create/reads/writes files on your local/external machine...

使用這兩個模塊,我們將拉取它然后保存它.

Using the two modules, we will pull it and then save it.

現(xiàn)在讓我們假設 url 是這個 meme.png(不和諧 png 附件)

Now lets assume url is this meme.png (discord png attachment)

let request = require(`request`);
let fs = require(`fs`);
function download(url){
    request.get(url)
        .on('error', console.error)
        .pipe(fs.createWriteStream('meme.png'));
}

瞧!我們現(xiàn)在有一個關于Doritos XD的meme.png圖片

and Voila! We now have a meme.png image about Doritos XD

這篇關于下載文件到本地計算機發(fā)送附加到消息不和諧的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網(wǎng)!

【網(wǎng)站聲明】本站部分內容來源于互聯(lián)網(wǎng),旨在幫助大家更快的解決問題,如果有圖片或者內容侵犯了您的權益,請聯(lián)系我們刪除處理,感謝您的支持!

相關文檔推薦

discord.js v12: How do I await for messages in a DM channel?(discord.js v12:我如何等待 DM 頻道中的消息?)
how to make my bot mention the person who gave that bot command(如何讓我的機器人提及發(fā)出該機器人命令的人)
How to fix Must use import to load ES Module discord.js(如何修復必須使用導入來加載 ES 模塊 discord.js)
How to list all members from a specific server?(如何列出來自特定服務器的所有成員?)
Discord bot: Fix ‘FFMPEG not found’(Discord bot:修復“找不到 FFMPEG)
Welcome message when joining discord Server using discord.js(使用 discord.js 加入 discord 服務器時的歡迎消息)
主站蜘蛛池模板: 久久精品色欧美aⅴ一区二区 | 亚洲国产一 | 成人在线免费网站 | 久久亚洲国产精品日日av夜夜 | 免费视频一区二区三区在线观看 | 欧美另类视频在线 | 久久高清免费视频 | 精品一区在线 | 久久久亚洲一区 | 99精品99| 日韩高清中文字幕 | 在线观看毛片网站 | 欧美日韩美女 | 国产一区二区在线视频 | 欧洲成人午夜免费大片 | 日韩欧美国产一区二区 | 亚洲日韩中文字幕一区 | 91麻豆精品国产91久久久资源速度 | 精品久 | 91国内外精品自在线播放 | 97视频在线免费 | 亚洲狠狠 | 欧美日韩综合 | 国产日韩欧美综合 | 国产香蕉视频在线播放 | 久久久久久久一区 | 国产欧美久久一区二区三区 | 一级毛片在线看 | 久久精品久久久 | 国产高清久久久 | 久久久久久国产一区二区三区 | 国产精品福利在线观看 | 男女午夜激情视频 | 国产一区久久 | 成人一区二区三区 | 日韩av一区二区在线观看 | 羞羞的视频在线观看 | 久久成人国产 | 免费黄色网址视频 | 国产ts人妖一区二区三区 | 三级黄片毛片 |