3 回答

TA贡献1798条经验 获得超7个赞
你可以这样做:
message.channel.send('I am Damabot, developed by Damadion!', { files: ['./DidYouThinkIAmTheRealFace.png'] });
它将文件直接添加到消息中,因此您不必创建附件。我用这个我的 BOT,它工作得很好。

TA贡献1806条经验 获得超5个赞
对我来说,以下代码有效:
const attachment = new Discord.MessageAttachment("url");
channel.send(attachment);
Discord.Attachment 被替换为 Discord.MessageAttachement

TA贡献1835条经验 获得超7个赞
Attachment是 Discord.js 中的一个类。除非您对 require 语句 ( const { Attachment } = require('discord.js'))使用解构赋值,否则Node.js 会尝试根据代码中的类构造一个 Attachment 对象。当它发现没有时,它会抛出您的错误。
如果你想坚持构造附件对象,你可以使用:
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);
后者允许您也发送一个嵌入(并且可能在您的嵌入中使用附件)。
添加回答
举报