"Attachment is not defined" in javascript discord bot 代码(使用 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, you can see in the docs for Attachment,附件的构造函数定义为 new Discord.Attachment(file, name);
(其中名称是可选参数)。您的问题是您没有将 Attachment 定义为 Discord 对象的对象,其中 Discord
定义为 const Discord = require('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, you can see in the docs for Attachment,附件的构造函数定义为 new Discord.Attachment(file, name);
(其中名称是可选参数)。您的问题是您没有将 Attachment 定义为 Discord 对象的对象,其中 Discord
定义为 const Discord = require('discord.js');