我正在嘗試制作一個機器人。當我輸入“.test”時,bot 會等待一個檔案。收到后,他必須向我發送一個 Discord 鏈接,我可以從中下載相同的檔案。但他只提到了我發送檔案的訊息。
在此之前,我以某種方式做到了并開始嘗試一些東西。之后,我無法得到相同的結果。
有我的代碼:
module.exports = {
commands: 'test',
callback: (message, arguments, text) => {
const msg_filter = (m) => m.author.id === message.author.id;
message.channel.awaitMessages({ filter: msg_filter, max: 1, time: 60000})
.then((collected) => {
console.log(collected.first())
console.log(collected.first().attachment)
console.log(collected.first().url)
console.log("finish")
}).catch('Error. No respond.')
}
}
控制臺輸出:
//First
attachments: Collection(1) [Map] {
'myId' => MessageAttachment {
attachment: 'https://cdn.discordapp.com/attachments/914907287603261510/myId/sample.pdf',
name: 'sample.pdf',
id: 'myId',
size: 3028,
url: 'https://cdn.discordapp.com/attachments/914907287603261510/myId/sample.pdf',
proxyURL: 'https://media.discordapp.net/attachments/914907287603261510/myId/sample.pdf',
height: null,
width: null,
contentType: 'application/pdf',
ephemeral: false
}
},
//Second
undefined
//Third
https://discord.com/channels/901476184532062209/914907287603261510/917789424857780224
uj5u.com熱心網友回復:
collected是一個包含被捕獲的每條訊息的集合,訊息也是channel.awaitMessages()如此collected.first()。要訪問此郵件的附件,這是一個集合,您需要這樣做collected.first().attachments(注意復數形式)。考慮到這一點,您可以在 for-each 回圈中管理每個附件,或者通過以下方式獲取第一個附件collected.first().attachments.first()
轉載請註明出處,本文鏈接:https://www.uj5u.com/gongcheng/375504.html
標籤:javascript 不和谐.js
上一篇:頁面重繪后更改輸入位置
