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 prefix.js under ./src/handlers/loaders, another prefix.js under ./src/events/client, and a prefix command ping.js under ./src/Commands/tools and now I'm facing errors when running it.. prefix.js under ./src/handlers/loaders
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)
}
})
}
}
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 under ./src/events/client
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!` })
}
}
}
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 under ./src/Commands/tools
module.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:
16 Replies
d.js toolkit
d.js toolkitβ€’16mo ago
- What's your exact discord.js npm list discord.js and node node -v version? - Not a discord.js issue? Check out #other-js-ts. - Consider reading #how-to-get-help to improve your question! - Explain what exactly your issue is. - Post the full error stack trace, not just the top part! - Show your code! - Issue solved? Press the button!
grass
grassβ€’16mo ago
show event.js
BIPRO
BIPROOPβ€’16mo ago
event.js under ./src/handlers/loaders
const chalk = require('chalk');
const fs = require('fs');
const Discord = require('discord.js');

module.exports = (client) => {

if (client.shard.ids[0] === 0) console.log(`\u001b[0m`);
if (client.shard.ids[0] === 0) console.log(chalk.blue(chalk.bold(`System`)), (chalk.white(`>>`)), (chalk.green(`Loading events`)), (chalk.white(`...`)))
if (client.shard.ids[0] === 0) console.log(`\u001b[0m`);

fs.readdirSync('./src/events').forEach(dirs => {
const events = fs.readdirSync(`./src/events/${dirs}`).filter(files => files.endsWith('.js'));

if (client.shard.ids[0] === 0) console.log(chalk.blue(chalk.bold(`System`)), (chalk.white(`>>`)), chalk.red(`${events.length}`), (chalk.green(`events of`)), chalk.red(`${dirs}`), (chalk.green(`loaded`)));

for (const file of events) {
const event = require(`../../events/${dirs}/${file}`);
const eventName = file.split(".")[0];
const eventUpperCase = eventName.charAt(0).toUpperCase() + eventName.slice(1);
if(Discord.Events[eventUpperCase] === undefined){
client.on(eventName, event.bind(null, client)).setMaxListeners(0);
}else {
client.on(Discord.Events[eventUpperCase], event.bind(null, client)).setMaxListeners(0);
}
};
});
}
const chalk = require('chalk');
const fs = require('fs');
const Discord = require('discord.js');

module.exports = (client) => {

if (client.shard.ids[0] === 0) console.log(`\u001b[0m`);
if (client.shard.ids[0] === 0) console.log(chalk.blue(chalk.bold(`System`)), (chalk.white(`>>`)), (chalk.green(`Loading events`)), (chalk.white(`...`)))
if (client.shard.ids[0] === 0) console.log(`\u001b[0m`);

fs.readdirSync('./src/events').forEach(dirs => {
const events = fs.readdirSync(`./src/events/${dirs}`).filter(files => files.endsWith('.js'));

if (client.shard.ids[0] === 0) console.log(chalk.blue(chalk.bold(`System`)), (chalk.white(`>>`)), chalk.red(`${events.length}`), (chalk.green(`events of`)), chalk.red(`${dirs}`), (chalk.green(`loaded`)));

for (const file of events) {
const event = require(`../../events/${dirs}/${file}`);
const eventName = file.split(".")[0];
const eventUpperCase = eventName.charAt(0).toUpperCase() + eventName.slice(1);
if(Discord.Events[eventUpperCase] === undefined){
client.on(eventName, event.bind(null, client)).setMaxListeners(0);
}else {
client.on(Discord.Events[eventUpperCase], event.bind(null, client)).setMaxListeners(0);
}
};
});
}
What next?
grass
grassβ€’16mo ago
you export an object, and Object.bind() isn’t a function
BIPRO
BIPROOPβ€’16mo ago
What's the solution then? event.js was working with no errors tho before I added prefix command
grass
grassβ€’16mo ago
log event then and show what the output is before you have the error
BIPRO
BIPROOPβ€’16mo ago
How to do that?πŸ˜…
grass
grassβ€’16mo ago
console.log
BIPRO
BIPROOPβ€’16mo ago
In which line?
grass
grassβ€’16mo ago
preferably 20
BIPRO
BIPROOPβ€’16mo ago
Sorry if I'm irritating, I'm just new. Can you add it and send me the code if you don't mind?πŸ˜…
grass
grassβ€’16mo ago
no
BIPRO
BIPROOPβ€’16mo ago
Uhk
BIPRO
BIPROOPβ€’16mo ago
grass
grassβ€’16mo ago
did you write this code?
BIPRO
BIPROOPβ€’16mo ago
Umm no
Want results from more Discord servers?
Add your server