首页 > 解决方案 > 如何使用我的机器人修复此“附件不是构造函数”错误?

问题描述

当我为 Discord 制作机器人并尝试附加图像时,由于这个错误我不能

这是一个运行在 Discord 上的机器人,Discord.js 我一开始就尝试了 const Attachment,但是没有用,在代码中删除 new 和 const 也没有用

        case 'about':
            message.channel.send('I am Damabot, developed by Damadion!')
            const attachment = new Attachment('./DidYouThinkIAmTheRealFace.png')
            message.channel.send('I am Damabot, developed by Damadion!' + attachment)
            console.log('Bot successfully replied')
            break;

我希望它发送附件,但它没有发送此错误

标签: javascriptdiscord.js

解决方案


你可以这样做:

message.channel.send('I am Damabot, developed by Damadion!', { files: ['./DidYouThinkIAmTheRealFace.png'] });

它将文件直接添加到消息中,因此您不必创建附件。我用这个我的 BOT,它工作得很好。


推荐阅读