Handling error?

I guess its an error in my command handler. as No commands will register
26 Replies
d.js toolkit
d.js toolkit2y ago
• What's your exact discord.js npm list discord.js and node node -v version? • Post the full error stack trace, not just the top part! • Show your code! • Explain what exactly your issue is. • Not a discord.js issue? Check out #useful-servers.
a
aOP2y ago
v14/11 v20 No error
const { run } = require("./util/taskMngr");



client.on("ready", () => {
debug(`Logged in as ${client.user.tag}!`);
run();
});

client.commands = new discord.Collection();

const commandFiles = fs
.readdirSync("./commands")
.filter((file) => file.endsWith(".js"));

for (const file of commandFiles) {
const filePath = path.join(__dirname, "commands", file);
const command = require(filePath);
client.commands.set(command.data.name, command);

if ("data" && "execute" in command) {
debug(`Loaded command ${command.data.name}`);
} else {
debug(`Failed to load command ${command.data.name}`);
}
}

client.on("messageCreate", async (message) => {

if (!message.content.startsWith(process.env.PREFIX) || message.author.bot) return;

const args = message.content
.slice(process.env.PREFIX.length)
.trim()
.split(/ +/);
const command = args.shift().toLowerCase();
if (!command) return;
try {
await command.execute(message);
} catch (error) {
debug(error);
message.reply("there was an error trying to execute that command!");
}
});

client.login(process.env.TOKEN);
const { run } = require("./util/taskMngr");



client.on("ready", () => {
debug(`Logged in as ${client.user.tag}!`);
run();
});

client.commands = new discord.Collection();

const commandFiles = fs
.readdirSync("./commands")
.filter((file) => file.endsWith(".js"));

for (const file of commandFiles) {
const filePath = path.join(__dirname, "commands", file);
const command = require(filePath);
client.commands.set(command.data.name, command);

if ("data" && "execute" in command) {
debug(`Loaded command ${command.data.name}`);
} else {
debug(`Failed to load command ${command.data.name}`);
}
}

client.on("messageCreate", async (message) => {

if (!message.content.startsWith(process.env.PREFIX) || message.author.bot) return;

const args = message.content
.slice(process.env.PREFIX.length)
.trim()
.split(/ +/);
const command = args.shift().toLowerCase();
if (!command) return;
try {
await command.execute(message);
} catch (error) {
debug(error);
message.reply("there was an error trying to execute that command!");
}
});

client.login(process.env.TOKEN);
a
aOP2y ago
a
aOP2y ago
initiates commands fine But as when you try to use them, it does nothing Here would be a command example
module.exports = {
data: {
name: 'help',
description: 'Help command',
},
async execute(message, args) {
const { MessageEmbed } = require('discord.js');
const embed = new MessageEmbed()
.setTitle('Help')
.setDescription('This is a list of all the commands')
.addField('claim', 'Claim a username')
.addField('help', 'Help command')

message.channel.send({ embeds: [embed] });
module.exports = {
data: {
name: 'help',
description: 'Help command',
},
async execute(message, args) {
const { MessageEmbed } = require('discord.js');
const embed = new MessageEmbed()
.setTitle('Help')
.setDescription('This is a list of all the commands')
.addField('claim', 'Claim a username')
.addField('help', 'Help command')

message.channel.send({ embeds: [embed] });
Danial
Danial2y ago
Where are you registering the commands?
a
aOP2y ago
Inside a folder called commands.
Danial
Danial2y ago
Do you have a deployment script or something?
a
aOP2y ago
Its finds the path just fine No, its ran locally Not dockerized or anything
Danial
Danial2y ago
You're not registering the commands anywhere though, only finding the files in the commands folder and putting them in the client.commands collection
a
aOP2y ago
does .set not register them?
d.js docs
d.js docs2y ago
guide Creating Your Bot: Registering slash commands read more
a
aOP2y ago
Im not using slash. Message commands hence the messageCreate not interaction
Danial
Danial2y ago
Oh, I see
a
aOP2y ago
i see no issue with the code but it wont work?
Danial
Danial2y ago
What do you mean by register though, you don't need to register commands when using message commands By the way, MessageEmbed was renamed to EmbedBuilder in v14
a
aOP2y ago
As in defining them
Danial
Danial2y ago
Also, what intents do you have, can you show your client constructor?
a
aOP2y ago
Should not matter, it is not reading any message I send All, 32057 bitfield I think that should be all anyway
d.js docs
d.js docs2y ago
We highly recommend only specifying the intents you actually need. - Note, that 98303, 32767 or whatever other magic number you read that represents "all intents", gets outdated as soon as new intents are introduced. - The number will always represent the same set of intents, and will not include new ones. There is no magic "all intents" bit.
Danial
Danial2y ago
That's not all
a
aOP2y ago
I swear if that was the reason i was erroring
Danial
Danial2y ago
Please only have the intents you need, use GatewayIntentBits enum
d.js docs
d.js docs2y ago
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]
});
Danial
Danial2y ago
I know but you might wanna fix that as well
a
aOP2y ago
yeah I will it was an intent error thank you so much
Danial
Danial2y ago
Of course
Want results from more Discord servers?
Add your server