Cześć, mam taki o to problem. Tworzę bota na discorda, mam główny plik main.js oraz inne pliki w kategorii komendy. Zrobiłem do tego czasu 3 różne komendy, które działają bez problemu; następnie chciałem zrobić komendę "afk", ale po wpisaniu "node ." w konsoli wyświetla mi się następujący błąd:
PS C:\Users\Brajan\Desktop\Kangaroobot> node .
internal/modules/cjs/loader.js:883
throw err;
^
Error: Cannot find module 'quick.db'
Require stack:
- C:\Users\Brajan\Desktop\Kangaroobot\commands\afk.js
- C:\Users\Brajan\Desktop\Kangaroobot\main.js
at Function.Module._resolveFilename (internal/modules/cjs/loader.js:880:15)
at Function.Module._load (internal/modules/cjs/loader.js:725:27)
at Module.require (internal/modules/cjs/loader.js:952:19)
at require (internal/modules/cjs/helpers.js:88:18)
at Object.<anonymous> (C:\Users\Brajan\Desktop\Kangaroobot\commands\afk.js:2:12)
at Module._compile (internal/modules/cjs/loader.js:1063:30)
at Object.Module._extensions..js (internal/modules/cjs/loader.js:1092:10)
at Module.load (internal/modules/cjs/loader.js:928:32)
at Function.Module._load (internal/modules/cjs/loader.js:769:14)
at Module.require (internal/modules/cjs/loader.js:952:19) {
code: 'MODULE_NOT_FOUND',
requireStack: [
'C:\\Users\\Brajan\\Desktop\\Kangaroobot\\commands\\afk.js',
'C:\\Users\\Brajan\\Desktop\\Kangaroobot\\main.js
próbowałem resintall programu node.js, usuwać pliki node_modules oraz package-lock.json a następnie instalować jeszcze raz komendą, ale nic nie działa..
pierwszy kod jest to main.js a drugi to afk.js (czyli komenda)
const Discord = require('discord.js');
const client = new Discord.Client();
const prefix = '-';
const fs = require('fs');
client.commands = new Discord.Collection();
const commandFiles = fs.readdirSync('./commands/').filter(file => file.endsWith('.js'));
for(const file of commandFiles){
const command = require(`./commands/${file}`);
client.commands.set(command.name, command);
}
//Console log
client.once('ready', () => {
console.log('Kangaroo bot is now online. *sigh*');
});
client.on('message', message => {
if(!message.content.startsWith(prefix) || message.author.bot) return;
const args = message.content.slice(prefix.length).split(/ +/);
const command = args.shift().toLowerCase();
if(command === 'clear'){
client.commands.get('clear').execute(message, args);
}
if(command === 'ping'){
client.commands.get('ping').execute(message, args);
}
if(command === 'ticket'){
client.commands.get('ticket').execute(message, args);
}
if(command === 'afk'){
client.commands.get('afk').execute(message, args);
}
});
client.login('kod...');
const discord = require('discord.js')
const db = require('quick.db')
module.exports.run = async (Client, message, args, prefix) => {
if(!message.content.startsWith(prefix)) return;
const content = args.join(" ")
await db.set(`afk-${message.author.id}+${message.guild.id}`, content)
message.channel.send(`you are now afk.\nReason: ${content}`)
}
module.exports.help = {
name: `afk`,
aliases: []
};