问题描述
每次在树莓派上运行index.js文件时都会出现此错误,但是当我在Windows 10中运行相同文件时没有错误
node index.js
内部/模块/cjs/loader.js:638 抛出错误 ^
错误:找不到模块'./commands/code.js'
我尝试重新安装node和npm
这是文件中的代码
文件== index.js
const Discord = require('discord.js');
const fs = require('fs')
const PREFIX = '!';
const d = new Date();
const bot = new Discord.Client();
const token = 'NzYzNDIzNjIwMTQzMTIwNDQ0.X33fpg.L5joItGS6keg9L6SqhW3B2pJVTA';
const commandFiles = fs.readdirSync('./Commands').filter(file => file.endsWith('.js'));
bot.commands = new Discord.Collection();
for (const file of commandFiles) {
const command = require(`./commands/${file}`);
bot.commands.set(command.name,command);
}
bot.on('ready',() => {
console.log('This Bot is Online');
//update(true)
})
//Commands
bot.on('message',async message => {
//Format & Execute command
if (!message.content.startsWith(PREFIX) || message.author.bot) return;
var parts = message.content.split('-');
const args = parts[0].slice(PREFIX.length).split(/ +/);
const command = args.shift().toLowerCase();
if (!bot.commands.has(command)) return;
try {
bot.commands.get(command).execute(message,args,parts);
} catch (error) {
console.log(error)
bot.commands.get('help').execute(message,parts);
}
})
文件== code.js
module.exports = {
name: 'codes',description: 'dsplay game code',execute(message,parts) {
const Discord = require('discord.js');
if (parts[1] == null) {
message.channel.send('Format: "!code-00000"(game code)');
}
else{
var Fcode = parts[1].toUpperCase();
const attachment = new Discord.MessageAttachment('./icons/' + 'game.png','game.png');
const code = new Discord.MessageEmbed()
.setTitle('Lets Play Among Us')
.setColor('#21EF39')
.addFields(
{ name: 'Game Code',value: Fcode })
.attachFiles(attachment)
.setThumbnail('attachment://game.png');
message.channel.send('@everyone')
message.channel.send(code);
}
}
}
解决方法
暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!
如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。
小编邮箱:dio#foxmail.com (将#修改为@)