【发布时间】:2021-01-31 14:15:26
【问题描述】:
我已经尝试了几次以使其工作,但无法弄清楚如何将机器人引导到正确的文件夹。
运行命令时总是出现这个错误
(node:15532) UnhandledPromiseRejectionWarning: Error: ENOENT: no such file or directory, stat 'c:\Users\Owner\Desktop\Discordbot\93c5b877d8afcf7a9590fcb149e849c53c6cc1ed.jpg'
有谁知道我做错了什么以及如何解决它?
const { Client, MessageAttachment } = require('discord.js');
var fs = require('fs');
var files = fs.readdirSync('./pics/'); // I thought this would direct it to where it neeeds to be
module.exports = {
execute(message, args){
var item = files[Math.floor(Math.random() * files.length)];
var item = new MessageAttachment(item);
message.channel.send(item)
}
}
请帮忙。
【问题讨论】:
-
文件夹“pics”是主根文件夹还是子文件夹?
-
与index.js和package.json在同一个文件夹
标签: node.js discord discord.js