我得到了这个错误,似乎机器人找不到图像。
如何定义图像的路径?它位于:C:\users\yanzi\desktop\laisabot\emotes
?
const Discord = require("discord.js");
const config = require("./config.json");
const client = new Discord.Client();
const prefix = "!";
client.on("message", function(message) {
if (message.author.bot) return;
if (!message.content.startsWith(prefix)) return;
const commandBody = message.content.slice(prefix.length);
const args = commandBody.split(' ');
const command = args.shift().toLowerCase();
if (command === "ping") {
const timeTaken = Date.now() - message.createdTimestamp;
message.reply(`Pong! This message had a latency of ${timeTaken}ms.`);
} else if (command === "sum") {
const numArgs = args.map(x => parseFloat(x));
const sum = numArgs.reduce((counter, x) => counter += x);
message.reply(`The sum of all the arguments you provided is ${sum}!`);
}
// If the message is '!rip'
else if (message.content === '!rip') {
// Create the attachment using MessageAttachment
const attachment = new MessageAttachment('./laisa2.png');
// Send the attachment in the message channel with a content
message.channel.send(`${message.author},`, attachment);
}
});
client.login(config.BOT_TOKEN);
您是在未定义MessageAttachment时调用它。
它是您在顶部需要的Discord libary的一部分,因此您有两个解决方案:
New Discord.MessageAttachment
代替New MessageAttachment
{MessageAttachment}
,请注意,在进一步向上调用Discord.client
时,还需要向该对象添加,client
和其他对象。这将导致const{MessageAttachment,Client}=require('discord.js');
我希望这能有所帮助,一定要阅读文档和检查一些教程。