How do I fix this error: "Error: Cannot find module './commands/info/status.js'" discordJS - discord.js

hander "command.js"
const { readdirSync } = require('fs');
const ascii = require('ascii-table');
const client = require('..');
const { dir } = require('console');
const { config } = require('process');
let table = new ascii("Commands");
table.setHeading('Commands', 'Load');
module.exports = (client) => {
readdirSync('./commands/').forEach(dir => {
const commands = readdirSync(`./commands/${dir}/`).filter(file => file.endsWith(".js"));
for(const file of commands) {
const pull = require(`./commands/${dir}/${file}`);
if (pull.name) {
client.commands.set(pull.name, pull);
slash.push(pull);
table.addRow(file, "OK");
}else {
table.addRow(file, 'Error - Missing a help.name or it is not a string...');
continue;
}if(pull.aliases && Array.isArray(pull.aliases)) pull.aliases.forEach(alias => client.aliases.set(alias, pull.name))
}
});
console.log(table.toString());
readdirSync('./events/').forEach((file) => {
const events = readdirSync('./events').filter((file) =>
file.endsWith('.js')
);
for (let file of events) {
let pull = require(`../events/${file}`);
if(pull.name) {
client.events.set(pull.name, pull)
}
}
console.log(`${file} Events load`);
})
}
event "messageCreate.js"
const { Embed, Collection } = require('discord.js')
const client = require('..');
const config = require('../setting/config.json');
const prefix_bot = config.prefix_bot;
client.on("messageCreste", async (message) => {
if(message.author.bot) return;
if(!message.content.startsWith(prefix_bot)) return;
if(!message.guild) return;
if(!message.member) message.member = await message.guild.fetchMember(message);
const args = message.content.slice(prefix_bot.length).trim().split(/ +/g);
const cmd = args.shift().toLowerCase();
if(cmd.length == 0) return;
let command = client.commands.get(cmd);
if(!command) command = client.commands.get(client.aliases.get(cmd));
if(command) command.run(client, message, args)
});
commands "status.js"
const { Embed, Collection } = require('discord.js')
const client = require('..');
const config = require('../setting/config.json');
const prefix_bot = config.prefix_bot;
client.on("messageCreste", async (message) => {
if(message.author.bot) return;
if(!message.content.startsWith(prefix_bot)) return;
if(!message.guild) return;
if(!message.member) message.member = await message.guild.fetchMember(message);
const args = message.content.slice(prefix_bot.length).trim().split(/ +/g);
const cmd = args.shift().toLowerCase();
if(cmd.length == 0) return;
let command = client.commands.get(cmd);
if(!command) command = client.commands.get(client.aliases.get(cmd));
if(command) command.run(client, message, args)
});
error
node:internal/modules/cjs/loader:936
throw err;
^
Error: Cannot find module './commands/info/status.js'
Require stack:
C:\Users\satang\Desktop\bot_node_satang\dis3\handler\command.js
C:\Users\satang\Desktop\bot_node_satang\dis3\index.js
at Function.Module._resolveFilename (node:internal/modules/cjs/loader:933:15)
at Function.Module._load (node:internal/modules/cjs/loader:778:27)
at Module.require (node:internal/modules/cjs/loader:1005:19)
at require (node:internal/modules/cjs/helpers:94:18)
at C:\Users\satang\Desktop\bot_node_satang\dis3\handler\command.js:15:26
at Array.forEach ()
at module.exports (C:\Users\satang\Desktop\bot_node_satang\dis3\handler\command.js:12:32)
at C:\Users\satang\Desktop\bot_node_satang\dis3\index.js:68:34
at Array.forEach ()
at Object. (C:\Users\satang\Desktop\bot_node_satang\dis3\index.js:67:13) {
code: 'MODULE_NOT_FOUND',
requireStack: [
'C:\Users\satang\Desktop\bot_node_satang\dis3\handler\command.js',
'C:\Users\satang\Desktop\bot_node_satang\dis3\index.js'
]
}
Can anyone find the error?
HELP ME PLESSS

Related

Discord.js V14 Bot Ping CMD

I am new to coding I was just making a simple ping command when I went to run it I got this error I have tried fixing it but I can't seem to find the problem please help me! I have been following this video (https://www.youtube.com/watch?v=6IgOXmQMT68&list=PLv0io0WjFNn9LDsv1W4fOWygNFzY342Jm&index=1).
ping.js:
const { SlashCommandBuilder } = require('discord.js');
module.exports = {
data: new SlashCommandBuilder()
.setName('ping')
.setDescription('Return my ping!'),
async execute(interaction, client) {
const messsage = await interaction.deferReply({
fetchReply: true
});
const newMessage = `API Latency: ${client.ws.ping}\nClient Ping: ${message.createdTimestamp - interaction.createdTimestamp}`
await interaction.editReply({
content: newMessage
});
}
}
handleEvents.js:
const fs = require("fs");
module.exports = (client) => {
client.handleEvents = async () => {
const eventFolders = fs.readdirSync(`./src/events`);
for (const folder of eventFolders) {
const eventFiles = fs
.readdirSync(`./src/events/${folder}`)
.filter((file) => file.endsWith(".js"));
switch (folder) {
case "client":
for (const file of eventFiles) {
const event = require(`../../events/${folder}/${file}`);
if (event.once)
client.once(event.name, (...args) =>
event.execute(...args, client)
);
else
client.on(event.name, (...args) =>
event.execute(...args, client)
);
}
break;
default:
break;
}
}
};
};
interactionCreate.js:
module.exports = {
name: "interactionCreate",
async execute(interaction, client) {
if (interaction.isChatInputCommand()) {
const { commands } = client;
const { commandName } = interaction;
const command = commands.get(commandName);
if (!command) return;
try {
await command.execute(interaction, client);
} catch (error) {
console.error(error);
await interaction.reply({
content: `Something went wrong while executing this command...`,
ephemeral: true,
});
}
}
},
};
Error:
TypeError: command.execute is not a function
at Object.execute (C:\Users\mikay\OneDrive\Desktop\v14 Bot\src\events\client\interactionCreate.js:11:23)
at Client.<anonymous> (C:\Users\mikay\OneDrive\Desktop\v14 Bot\src\functions\handlers\handleEvents.js:20:23)
at Client.emit (node:events:513:28)
at InteractionCreateAction.handle (C:\Users\mikay\OneDrive\Desktop\v14 Bot\node_modules\discord.js\src\client\actions\InteractionCreate.js:81:12)
at Object.module.exports [as INTERACTION_CREATE] (C:\Users\mikay\OneDrive\Desktop\v14 Bot\node_modules\discord.js\src\client\websocket\handlers\INTERACTION_CREATE.js:4:36)
at WebSocketManager.handlePacket (C:\Users\mikay\OneDrive\Desktop\v14 Bot\node_modules\discord.js\src\client\websocket\WebSocketManager.js:352:31)
at WebSocketShard.onPacket (C:\Users\mikay\OneDrive\Desktop\v14 Bot\node_modules\discord.js\src\client\websocket\WebSocketShard.js:480:22)
at WebSocketShard.onMessage (C:\Users\mikay\OneDrive\Desktop\v14 Bot\node_modules\discord.js\src\client\websocket\WebSocketShard.js:320:10)
at WebSocket.onMessage (C:\Users\mikay\OneDrive\Desktop\v14 Bot\node_modules\ws\lib\event-target.js:199:18)
at WebSocket.emit (node:events:513:28)
Remove await on 11
commands.set(command.data.name, commands);
remove s from the last command

'message.reply not defined' discord.js v13

So I'm creating a bot with a handler online, and I'm trying to send an embed through message.reply, but it comes and error saying 'reply' is not defined. Here is the code:
const { Discord, MessageEmbed } = require('discord.js')
module.exports = {
callback: async ({ client, message, ...args }) => {
const embed = new MessageEmbed()
.setAuthor({
name: 'ยป Ping',
iconURL: client.user.defaultAvatarURL
})
.setTitle('Calculating ping...')
.setColor('GREEN')
message.reply({
embeds: [embed]
})
}
}
And here is the handler:
const fs = require('fs')
const getFiles = require('./get-files')
module.exports = (client) => {
const commands = {}
const suffix = '.js'
const commandFiles = getFiles('./commands', suffix)
for (const command of commandFiles) {
let commandFile = require(command)
if (commandFile.default) commandFile = commandFile.default
const split = command.replace(/\\/g, '/').split('/')
const commandName = split[split.length - 1].replace(suffix, '')
commands[commandName.toLowerCase()] = commandFile
}
client.on('messageCreate', (message) => {
if (message.author.bot || !message.content.startsWith('!')) {
return
}
const args = message.content.slice(1).split(/ +/)
const commandName = args.shift().toLowerCase()
if (!commands[commandName]) {
return
}
try {
commands[commandName].callback(client, message, ...args)
} catch (err) {
console.error('[ERROR]', err)
}
})
}
I would appreciate if you found out.
Thanks!

discord js v13 message reply don't work (prefix)

I was making discord bot that reply the user word with prefix.
example the user said !Hello the bot will reply with Hello
The error was
(node:11208) DeprecationWarning: The message event is deprecated. Use messageCreate instead (Use node --trace-deprecation ... to show where the warning was created)
So I changed the code message to messageCreate but the bot didn't reply either and have no error in the console log what should I change the code of my script?
this is the source code
prefix is ! (It is in the config.json)
index.js
const {Client,Intents,Collection} = require("discord.js");
const client = new Client ({intents:[Intents.FLAGS.GUILDS,Intents.FLAGS.GUILD_MESSAGES,Intents.FLAGS.GUILD_MEMBERS]})
const fs = require("fs");
const { token, prefix } = require("./config.json");
client.commands = new Collection();
const commandFiles = fs.readdirSync("./commands").filter((file) => file.endsWith(".js"));
var data = []
for(const file of commandFiles) {
const command = require(`./commands/${file}`);
client.commands.set(command.name, command);
data.push({name:command.name,description:command.description,options:command.options});
}
client.once('ready', async () =>{
console.log(`Logged in as ${client.user.tag}`)
// await client.guilds.cache.get('874178319434801192')?.commands.set(data)
setInterval(() => {
const statuses = [
'mimc!',
'wtf',
'prefix = !'
]
const status = statuses[Math.floor(Math.random()*statuses.length)]
client.user.setActivity(status, {type: "PLAYING"})
}, 10000)
});
client.on("messageCreate", (message) =>{
if(!message.content.startsWith(prefix) || message.author.bot) return;
const args = message.content.slice(prefix.length).trim().split(/ +/);
const command = args.shift();
if(!client.commands.has(command)) return;
try{
client.commands.get(command).execute(message, args);
}
catch(error){
console.error(error);
}
});
client.login(token)
Hello.js (in the folder of commands)
module.exports = {
name: "Hello",
description: "Say Hi",
execute(message) {
return message.channel.send(`${message.author}, Hello.`)
},
};
The code of index.js (or main file) goes by:
const {Client, Intents, MessageEmbed, Presence, Collection, Interaction}= require ('discord.js')
const client = new Client({intents:[Intents.FLAGS.GUILDS, Intents.FLAGS.GUILD_MESSAGES]})
const TOKEN = ''// get your TOKEN!
const PREFIX = '!'
const fs = require('fs')
client.commands = new 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);
}
client.on('ready', ()=> {
console.log('๐Ÿ• I am online!!')
client.user.setActivity('A GAME ', {type: ('PLAYING')})
client.user.setPresence({
status: 'Online'
})
})
client.on('message', message => {
if(!message.content.startsWith(PREFIX)|| message.author.bot) return
const arg = message.content.slice(PREFIX.length).split(/ +/)
const command= arg.shift().toLowerCase()
if (command === 'ping'){
client.commands.get('ping').execute(message,arg)
}
})
client.login(TOKEN)
After making a folder commands, add a new .js file, and name it as ping.js
The code for ping.js goes by -
module.exports={
name:'ping',
execute(message, arg){
message.reply('hello!!')
}
}

Discord.js - Discord bot stopped responding to commands

I was trying to add some new features to my bot, and it didn't end up working. So I removed the new code, and now it won't respond to any commands. It's still online but as I said earlier, it's completely unresponsive. I've looked through the code and I can't find the issue. I'm still new to coding bots so I'm probably missing something.
Here's my main code file:
const fs = require('fs');
const Discord = require('discord.js');
const { prefix, token } = require('./config.json');
const client = new Discord.Client();
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);
}
client.once('ready', () => {
console.log('Ready!');
});
client.on('message', message => {
console.log(message)
if (!message.content.startsWith(prefix) || message.author.bot) return;
const args = message.content.slice(prefix.length).trim().split(/ +/);
const command = args.shift().toLowerCase();
if (!client.commands.has(command)) return;
try {
client.commands.get(command).execute(message, args);
} catch (error) {
console.error(error);
message.reply('there was an error trying to execute that command!');
}
});
client.login(token);
And here's a command file:
function pickOneFrom(array) {
function pickOneFrom(array) {
return array[Math.floor(Math.random() * array.length)];
}
module.exports = {
name: 'throw',
description: 'this is a throw command!',
execute(message, args) {
const responses = ['a apple', 'a melon', 'a potato', 'a snowball', 'a spanner', 'a computer'];
message.channel.send(
`${message.author} threw ${pickOneFrom(responses)} at ${
message.mentions.users.first() ?? 'everyone'
}!`,
);
},
};```
After looking your code I see that you didn't import fs file system to reading commands files to import so you should add it into your code
const fs = require('fs');
const Discord = require('discord.js');
const { prefix, token } = require('./config.json');
const client = new Discord.Client();
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);
}
client.once('ready', () => {
console.log('Ready!');
});
client.on('message', message => {
if (!message.content.startsWith(prefix) || message.author.bot) return;
const args = message.content.slice(prefix.length).trim().split(/ +/);
const command = args.shift().toLowerCase();
if (!client.commands.has(command)) return;
try {
client.commands.get(command).execute(message, args);
} catch (error) {
console.error(error);
message.reply('there was an error trying to execute that command!');
}
});
client.login(token);
const fs = require('fs');
const Discord = require('discord.js');
const { prefix, token } = require('./config.json');
const client = new Discord.Client();
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);
}
client.once('ready', () => {
console.log('Ready!');
});
client.on('message', message => {
if (!message.content.startsWith(prefix) || message.author.bot) return;
const args = message.content.slice(prefix.length).trim().split(/ +/);
const command = args.shift().toLowerCase();
if (!client.commands.has(command)) return;
try {
client.commands.get(command).execute(client , message , args);
} catch (error) {
console.error(error);
message.reply('there was an error trying to execute that command!');
}
});
client.login(token);
You forgot to add client at client.commands.get(command).execute(message , args)

DiscordJs Event Handler With SubFolders And Aliases

I have the following code which i have from a tutorial. I would like to extend it so there are subfolders (instead of just one command folder) and aliases if the user knows a different and shorter name for the command.
I added aliases and modules line, but am not sure how to implement those in in code that i have.
const fs = require('fs');
const Discord = require('discord.js');
const { prefix } = require('./config.json');
const modules = ["administration", "fun", "misc", "information"];
const client = new Discord.Client();
client.commands = new Discord.Collection();
client.aliases = 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);
}
client.once('ready', () => {
console.log('Philomena is ready for action!');
client.user.setActivity("`ph.help`")
.then(console.log)
.catch(console.error);
});
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 (!client.commands.has(command)) return;
try {
client.commands.get(command).execute(message, args);
} catch (error) {
console.error(error);
message.reply('there was an error trying to execute that command!');
}
});
client.login(process.env.BOT_TOKEN);
You can just repeat what you already have for every sub-folder:
const subCommandACmds = fs.readdirSync('./commands/subCommandA').filter(file => file.endsWith('.js'));
for (const file of subCommandACmds) {
const command = require(`./commands/subCommandA/${file}`);
client.commands.set(command.name, command);
}
const subCommandBCmds = fs.readdirSync('./commands/subCommandB').filter(file => file.endsWith('.js'));
for (const file of subCommandBCmds) {
const command = require(`./commands/subCommandB/${file}`);
client.commands.set(command.name, command);
}
To have your bot also retrieve the commands from subfolders, you could use a function like this:
client.commands=new Discord.Collection();
loadCommands(client.commands, './commands');
function loadCommands(collection, directory){
const files = fs.readdirSync(directory);
for (const file of files) {
const path=`${directory}/${file}`;
if(file.endsWith('.js')){
const command = require(path);
collection.set(command.name, command);
}
else if(fs.lstatSync(path).isDirectory()){
loadCommands(collection, path);
}
}
};

Resources