【问题标题】:"Attachment is not defined" in javascript code for discord bot (using discord.js)discord bot的javascript代码中的“附件未定义”(使用discord.js)
【发布时间】:2019-10-24 21:28:25
【问题描述】:

我第一次尝试不和谐机器人的功能。我直接从 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 discord.js


    【解决方案1】:

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

    【讨论】:

    • 很高兴我能帮上忙 :)
    猜你喜欢
    • 2018-05-31
    • 2021-04-16
    • 2021-01-16
    • 2022-01-21
    • 2019-03-25
    • 2022-01-13
    • 2021-10-28
    • 2019-01-17
    • 2021-06-28
    相关资源
    最近更新 更多