繁体   English   中英

discord 机器人的 javascript 代码中的“附件未定义”(使用 discord.js)

[英]“Attachment is not defined” in javascript code for discord bot (using discord.js)

我第一次尝试 discord 机器人的功能。 我直接从 discord.js 文档中的示例复制并粘贴了代码,但遇到了错误。

代码:

if (message.content === '!rip') {
            // Create the attachment using Attachment
            const attachment = new Attachment('https://i.imgur.com/w3duR07.png');
            // Send the attachment in the message channel
            message.channel.send(attachment);
        }

错误信息:

ReferenceError: Attachment is not defined
    at Client.bot.on.message (C:\Code\ACCBot\bot.js:36:28)
    at Client.emit (events.js:194:15)
    at MessageCreateHandler.handle (C:\Code\ACCBot\node_modules\discord.js\src\client\websocket\packets\handlers\MessageCreate.js:9:34)
    at WebSocketPacketManager.handle (C:\Code\ACCBot\node_modules\discord.js\src\client\websocket\packets\WebSocketPacketManager.js:105:65)
    at WebSocketConnection.onPacket (C:\Code\ACCBot\node_modules\discord.js\src\client\websocket\WebSocketConnection.js:333:35)
    at WebSocketConnection.onMessage (C:\Code\ACCBot\node_modules\discord.js\src\client\websocket\WebSocketConnection.js:296:17)
    at WebSocket.onMessage (C:\Code\ACCBot\node_modules\discord.js\node_modules\ws\lib\event-target.js:120:16)
    at WebSocket.emit (events.js:189:13)
    at Receiver.receiverOnMessage (C:\Code\ACCBot\node_modules\discord.js\node_modules\ws\lib\websocket.js:789:20)
    at Receiver.emit (events.js:189:13)

当我输入 !rip 时发生错误

任何帮助将不胜感激,在此先感谢。

查看Discord.JS Docs ,您可以在Attachment 的文档中看到,附件的构造函数定义为new Discord.Attachment(file, name); (其中 name 是可选参数)。 Your issue is that you are not defining Attachment as an object of the Discord object, where Discord is defined as const Discord = require('discord.js');

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM