How do I add prefix commands to my bot mostly working on slash commands?
Hey, so I was trying to add prefix commands to my slash commands based bot by following a TUTORIAL, which led to me just running errors at this point.. for this, I created
AND NOW HERE'S THE ERROR I'M FACING:
prefix.jsprefix.js under ./src/handlers/loaders./src/handlers/loaders, another prefix.jsprefix.js under ./src/events/client./src/events/client, and a prefix command ping.jsping.js under ./src/Commands/tools./src/Commands/tools and now I'm facing errors when running it..prefix.js
prefix.js
under ./src/handlers/loaders
./src/handlers/loaders
prefix.jsprefix.js./src/handlers/loaders./src/handlers/loadersconst fs = require('fs')
module.exports = (client) => {
const interactionLogs = new Discord.WebhookClient({
id: client.webhooks.interactionLogs.id,
token: client.webhooks.interactionLogs.token,
});
const commands = [];
if (client.shard.ids[0] === 0) console.log(chalk.blue(chalk.bold(`System`)), (chalk.white(`>>`)), (chalk.green(`Loading prefix commands.`)), (chalk.white(`...`)))
if (client.shard.ids[0] === 0) console.log(`\u001b[0m`);
fs.readdirSync('./src/Commands').forEach(dirs => {
client.prefixCommands = async (commandFolders, path) => {
client.prefixArray = [];
for (folder of commandFolders) {
const commandFiles = fs.readdirSync('./src/Commands').filter(file => file.endsWith('.js'));
if (client.shard.ids[0] === 0) console.log(chalk.blue(chalk.bold(`System`)), (chalk.white(`>>`)), chalk.red(`${commandFiles.length}`), (chalk.green(`commands of`)), chalk.red(`${dirs}`), (chalk.green(`loaded`)));
for (const file in commandFiles) {
const command = require(`../Commanands/${folder}/${file}`);
client.pcommands.set(command.name, command);
client.prefixArray.push(command);
if (command.aliases && Array.isArray(command.aliases)) {
command.aliases.forEach(alias) => {
client.aliases.set (alias, command.name)
}
}
}
}
(async () => {
try {
console.log("Started refreshing prefix commands.");
console.log("Successfully reloaded prefix commands.")
} catch (err) {
console.log(err)
}
})
}
}const fs = require('fs')
module.exports = (client) => {
const interactionLogs = new Discord.WebhookClient({
id: client.webhooks.interactionLogs.id,
token: client.webhooks.interactionLogs.token,
});
const commands = [];
if (client.shard.ids[0] === 0) console.log(chalk.blue(chalk.bold(`System`)), (chalk.white(`>>`)), (chalk.green(`Loading prefix commands.`)), (chalk.white(`...`)))
if (client.shard.ids[0] === 0) console.log(`\u001b[0m`);
fs.readdirSync('./src/Commands').forEach(dirs => {
client.prefixCommands = async (commandFolders, path) => {
client.prefixArray = [];
for (folder of commandFolders) {
const commandFiles = fs.readdirSync('./src/Commands').filter(file => file.endsWith('.js'));
if (client.shard.ids[0] === 0) console.log(chalk.blue(chalk.bold(`System`)), (chalk.white(`>>`)), chalk.red(`${commandFiles.length}`), (chalk.green(`commands of`)), chalk.red(`${dirs}`), (chalk.green(`loaded`)));
for (const file in commandFiles) {
const command = require(`../Commanands/${folder}/${file}`);
client.pcommands.set(command.name, command);
client.prefixArray.push(command);
if (command.aliases && Array.isArray(command.aliases)) {
command.aliases.forEach(alias) => {
client.aliases.set (alias, command.name)
}
}
}
}
(async () => {
try {
console.log("Started refreshing prefix commands.");
console.log("Successfully reloaded prefix commands.")
} catch (err) {
console.log(err)
}
})
}
}prefix.js
prefix.js
under ./src/events/client
./src/events/client
prefix.jsprefix.js./src/events/client./src/events/clientconst prefix = '?'
module.exports = {
name: 'messageCreate',
run: async (message, client) => {
if (message.author.bot) return;
if (!message.content.startsWith('?')) return;
const args = message.content.slice(prefix.length).trim().split(/ +/);
let cmd = args.shift().toLowerCase();
if (cmd.length === 0) return;
let command = client.pcommands.get(cmd);
if (!command) command = client.pcommands.get(client.aliases.get(cmd));
if (!command) return;
try {
await command.run(message, client, args)
} catch (err) {
console.log(err)
await message.reply({ content: `Something went wrong!` })
}
}
}const prefix = '?'
module.exports = {
name: 'messageCreate',
run: async (message, client) => {
if (message.author.bot) return;
if (!message.content.startsWith('?')) return;
const args = message.content.slice(prefix.length).trim().split(/ +/);
let cmd = args.shift().toLowerCase();
if (cmd.length === 0) return;
let command = client.pcommands.get(cmd);
if (!command) command = client.pcommands.get(client.aliases.get(cmd));
if (!command) return;
try {
await command.run(message, client, args)
} catch (err) {
console.log(err)
await message.reply({ content: `Something went wrong!` })
}
}
}ping.js
ping.js
under ./src/Commands/tools
./src/Commands/tools
ping.jsping.js./src/Commands/tools./src/Commands/toolsmodule.export = {
name: "ping",
description: "Pong!",
run: async (message, client, args) => {
message.reply({ content: "Pong!"})
}
}module.export = {
name: "ping",
description: "Pong!",
run: async (message, client, args) => {
message.reply({ content: "Pong!"})
}
}AND NOW HERE'S THE ERROR I'M FACING:

