I want to have a text command handler separate from my present slash command handler.

Hi! I was originally a djsv12 developer but now we've moved to v14 I still want to use prefix commands aswell. I know how to reply specifically, but I want an actual handler. I tried something but it doesn't seem to listen to the commands. Here is my actual text handler :
const { Message, Discord } = require("discord.js");

module.exports = {
name: "messageCreate",
/**
*
* @param {Message} message
*/
execute(Discord, client, message) {
if (message.author.bot) return;
if (!message.content.startsWith(client.config.PREFIX)) return;

const args = message.content.slice(prefix.length).trim().split(/ +/g);
const command = args.shift().toLowerCase();
const cmd = client.commands.get(command, interaction.commandName);
if (cmd.developer && !client.config.DEVID.includes(interaction.user.id))
return message.reply({
content: ":x: This command is only available to developers.",
ephemeral: true,
});

if (cmd.owneronly && interaction.user.id !== client.config.OWNERID)
return message.reply({
content: ":x: This command is only available to the owner.",
ephemeral: true,
});
cmd.execute(client, message, args, Discord);
},
};
const { Message, Discord } = require("discord.js");

module.exports = {
name: "messageCreate",
/**
*
* @param {Message} message
*/
execute(Discord, client, message) {
if (message.author.bot) return;
if (!message.content.startsWith(client.config.PREFIX)) return;

const args = message.content.slice(prefix.length).trim().split(/ +/g);
const command = args.shift().toLowerCase();
const cmd = client.commands.get(command, interaction.commandName);
if (cmd.developer && !client.config.DEVID.includes(interaction.user.id))
return message.reply({
content: ":x: This command is only available to developers.",
ephemeral: true,
});

if (cmd.owneronly && interaction.user.id !== client.config.OWNERID)
return message.reply({
content: ":x: This command is only available to the owner.",
ephemeral: true,
});
cmd.execute(client, message, args, Discord);
},
};
(1/...)
5 Replies
Unknown User
Unknown User3y ago
Message Not Public
Sign In & Join Server To View
kama
kamaOP3y ago
And this is my slash command handler :
const { ChatInputCommandInteraction } = require("discord.js");

module.exports = {
name: "interactionCreate",
/**
*
* @param {ChatInputCommandInteraction} interaction
*/
execute(interaction, client) {
if (!interaction.isChatInputCommand()) return;

const command = client.commands.get(interaction.commandName);
if (!command)
return interaction.reply({
content: "Command Outdated.",
ephemeral: true,
});

if (command.developer && !client.config.DEVID.includes(interaction.user.id))
return interaction.reply({
content: ":x: This command is only available to developers.",
ephemeral: true,
});

if (command.owneronly && interaction.user.id !== client.config.OWNERID)
return interaction.reply({
content: ":x: This command is only available to the owner.",
ephemeral: true,
});

const subCommand = interaction.options.getSubcommand(false);
if (subCommand) {
const subCommandFile = client.subCommands.get(
`${interaction.commandName}.${subCommand}`
);
if (!subCommand)
return interaction.reply({
content: "Subcommand Outdated.",
ephemeral: true,
});
subCommandFile.execute(interaction, client);
} else command.execute(interaction, client);
},
};
const { ChatInputCommandInteraction } = require("discord.js");

module.exports = {
name: "interactionCreate",
/**
*
* @param {ChatInputCommandInteraction} interaction
*/
execute(interaction, client) {
if (!interaction.isChatInputCommand()) return;

const command = client.commands.get(interaction.commandName);
if (!command)
return interaction.reply({
content: "Command Outdated.",
ephemeral: true,
});

if (command.developer && !client.config.DEVID.includes(interaction.user.id))
return interaction.reply({
content: ":x: This command is only available to developers.",
ephemeral: true,
});

if (command.owneronly && interaction.user.id !== client.config.OWNERID)
return interaction.reply({
content: ":x: This command is only available to the owner.",
ephemeral: true,
});

const subCommand = interaction.options.getSubcommand(false);
if (subCommand) {
const subCommandFile = client.subCommands.get(
`${interaction.commandName}.${subCommand}`
);
if (!subCommand)
return interaction.reply({
content: "Subcommand Outdated.",
ephemeral: true,
});
subCommandFile.execute(interaction, client);
} else command.execute(interaction, client);
},
};
(2/...) A normal slash command looks like this :
module.exports = {
developer: true,
data: new SlashCommandBuilder()
.setName("emit")
.setDescription("Emit the guildMemberAdd / Remove events")
.setDefaultMemberPermissions(PermissionFlagsBits.ManageGuild)
.setDMPermission(false),
/**
*
* @param {ChatInputCommandInteraction} interaction
* @param {Client} client
*/
execute(interaction, client) {
client.emit("guildMemberRemove", interaction.member);
client.emit("guildMemberAdd", interaction.member);

interaction.reply({
content: "Emitted GuidlMemberAdd and GuildMemberRemove",
ephemeral: true,
});
},
};
module.exports = {
developer: true,
data: new SlashCommandBuilder()
.setName("emit")
.setDescription("Emit the guildMemberAdd / Remove events")
.setDefaultMemberPermissions(PermissionFlagsBits.ManageGuild)
.setDMPermission(false),
/**
*
* @param {ChatInputCommandInteraction} interaction
* @param {Client} client
*/
execute(interaction, client) {
client.emit("guildMemberRemove", interaction.member);
client.emit("guildMemberAdd", interaction.member);

interaction.reply({
content: "Emitted GuidlMemberAdd and GuildMemberRemove",
ephemeral: true,
});
},
};
(3/...) And a normal text command like this :
const premiumSchema = require("../../Models/premium");
const { Client, Message, EmbedBuilder } = require("discord.js");

module.exports = {
name: "add-premium",
/**
*
* @param {Client} client
* @param {Message}} message
* @param {String[]} args
* @returns
*/
async execute(client, message, args) {
if (!client.config.DEVID.includes(message.user.id)) return;

const member =
message.mentions.members.first() ||
message.guild.members.cache.get(args[0]);

if (!member) message.reply("Please specify a valid member");

premiumSchema.findOne(
{
User: member.id,
},
async (err, data) => {
if (data)
return message.channel.send(
"User has already access to premium features."
);

new premiumSchema({
User: member.id,
}).save();
return message.channel.send(`Added ${user} to the database.`);
}
);
},
};
const premiumSchema = require("../../Models/premium");
const { Client, Message, EmbedBuilder } = require("discord.js");

module.exports = {
name: "add-premium",
/**
*
* @param {Client} client
* @param {Message}} message
* @param {String[]} args
* @returns
*/
async execute(client, message, args) {
if (!client.config.DEVID.includes(message.user.id)) return;

const member =
message.mentions.members.first() ||
message.guild.members.cache.get(args[0]);

if (!member) message.reply("Please specify a valid member");

premiumSchema.findOne(
{
User: member.id,
},
async (err, data) => {
if (data)
return message.channel.send(
"User has already access to premium features."
);

new premiumSchema({
User: member.id,
}).save();
return message.channel.send(`Added ${user} to the database.`);
}
);
},
};
This is my ascii table :
async function loadCommands(client) {
const { loadFiles } = require("../Functions/fileLoader");
const ascii = require("ascii-table");
const table = new ascii().setHeading("Commands", "Status");

await client.commands.clear();
await client.subCommands.clear();

let commandsArray = [];

const Files = await loadFiles("Commands");

Files.forEach((file) => {
const command = require(file);

if (command.subCommand)
return client.subCommands.set(command.subCommand, command);
if (!command.data) return;
else client.commands.set(command.data.name, command);

commandsArray.push(command.data.toJSON());

table.addRow(command.data.name, "✅");
table.addRow(command.name, "✅");
});

client.application.commands.set(commandsArray);

return console.log(table.toString(), "\n✅ Loaded Commands");
}

module.exports = { loadCommands };
async function loadCommands(client) {
const { loadFiles } = require("../Functions/fileLoader");
const ascii = require("ascii-table");
const table = new ascii().setHeading("Commands", "Status");

await client.commands.clear();
await client.subCommands.clear();

let commandsArray = [];

const Files = await loadFiles("Commands");

Files.forEach((file) => {
const command = require(file);

if (command.subCommand)
return client.subCommands.set(command.subCommand, command);
if (!command.data) return;
else client.commands.set(command.data.name, command);

commandsArray.push(command.data.toJSON());

table.addRow(command.data.name, "✅");
table.addRow(command.name, "✅");
});

client.application.commands.set(commandsArray);

return console.log(table.toString(), "\n✅ Loaded Commands");
}

module.exports = { loadCommands };
kama
kamaOP3y ago
And it returns this :
kama
kamaOP3y ago
I use NodeJS v16.15.0 and discord.js v14.7.1 The bot seems to not handle text commands.
d.js docs
d.js docs3y ago
Tag suggestion for @lordkama: If you aren't getting content, embeds or attachments of a message, make sure you have the MessageContent intent enabled in the Developer Portal and provide it to your client:
const { Client, GatewayIntentBits } = require('discord.js');
const client = new Client({
intents: [GatewayIntentBits.Guilds, GatewayIntentBits.GuildMessages, GatewayIntentBits.MessageContent]
});
const { Client, GatewayIntentBits } = require('discord.js');
const client = new Client({
intents: [GatewayIntentBits.Guilds, GatewayIntentBits.GuildMessages, GatewayIntentBits.MessageContent]
});

Did you find this page helpful?