3 回答

TA貢獻1798條經(jīng)驗 獲得超7個贊
你可以這樣做:
message.channel.send('I am Damabot, developed by Damadion!', { files: ['./DidYouThinkIAmTheRealFace.png'] });
它將文件直接添加到消息中,因此您不必創(chuàng)建附件。我用這個我的 BOT,它工作得很好。

TA貢獻1806條經(jīng)驗 獲得超5個贊
對我來說,以下代碼有效:
const attachment = new Discord.MessageAttachment("url");
channel.send(attachment);
Discord.Attachment 被替換為 Discord.MessageAttachement

TA貢獻1835條經(jīng)驗 獲得超7個贊
Attachment是 Discord.js 中的一個類。除非您對 require 語句 ( const { Attachment } = require('discord.js'))使用解構(gòu)賦值,否則Node.js 會嘗試根據(jù)代碼中的類構(gòu)造一個 Attachment 對象。當(dāng)它發(fā)現(xiàn)沒有時,它會拋出您的錯誤。
如果你想堅持構(gòu)造附件對象,你可以使用:
const attachment = new Discord.Attachment('./path/to/file.png', 'name'); // name is optional
message.channel.send('Hey there', attachment)
.catch(console.error);
否則,您可以files像這樣使用消息的屬性:
message.channel.send('Hey there', {
files: ['./path/to/file.png']
})
.catch(console.error);
后者允許您也發(fā)送一個嵌入(并且可能在您的嵌入中使用附件)。
添加回答
舉報