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

问题描述 投票:-1回答:1

[我在不和谐的bot上进行了一些首次尝试。我直接从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时发生错误

非常感谢,谢谢您。

javascript discord attachment
1个回答
0
投票

[查看Discord.JS Docs,您可以在docs for Attachment中看到,附件的构造函数定义为new Discord.Attachment(file, name);(名称是可选参数)。您的问题是您没有将附件定义为Discord对象的对象,其中Discord定义为const Discord = require('discord.js');

© www.soinside.com 2019 - 2024. All rights reserved.