"Attachment is not defined" 在 JavaScript 代码中为 Discord bot (使用 Discord.js)



我第一次尝试使用discordbot的功能。我直接从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:CodeACCBotbot.js:36:28)
at Client.emit (events.js:194:15)
at MessageCreateHandler.handle (C:CodeACCBotnode_modulesdiscord.jssrcclientwebsocketpacketshandlersMessageCreate.js:9:34)
at WebSocketPacketManager.handle (C:CodeACCBotnode_modulesdiscord.jssrcclientwebsocketpacketsWebSocketPacketManager.js:105:65)
at WebSocketConnection.onPacket (C:CodeACCBotnode_modulesdiscord.jssrcclientwebsocketWebSocketConnection.js:333:35)
at WebSocketConnection.onMessage (C:CodeACCBotnode_modulesdiscord.jssrcclientwebsocketWebSocketConnection.js:296:17)
at WebSocket.onMessage (C:CodeACCBotnode_modulesdiscord.jsnode_moduleswslibevent-target.js:120:16)
at WebSocket.emit (events.js:189:13)
at Receiver.receiverOnMessage (C:CodeACCBotnode_modulesdiscord.jsnode_moduleswslibwebsocket.js:789:20)
at Receiver.emit (events.js:189:13)

当我键入时出错!撕裂

如有任何帮助,我们将不胜感激,并提前表示感谢。

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

相关内容

  • 没有找到相关文章

最新更新