Error with a command

Here is my code:
const { SlashCommandBuilder } = require('discord.js');
const mysql = require('mysql2/promise');
const axios = require('axios');

const pool = mysql.createPool({
host: 'your-database-host',
user: 'your-database-user',
password: 'your-database-password',
database: 'your-database-name'
});

const PTERO_API_URL = 'https://pterodactyl-instance.com/api/application';
const PTERO_API_KEY = 'pterodactyl-api-key';

module.exports = {
name: 'register',
description: 'Register a user for the server',

async execute(interaction) {
const discordId = interaction.user.id;
const username = interaction.user.username;

try {
const [rows] = await pool.query('SELECT * FROM users WHERE discord_id = ?', [discordId]);

if (rows.length > 0) {
await interaction.reply(`User with Discord ID ${discordId} already exists!`);
return;
}

const response = await axios.post(`${PTERO_API_URL}/users`, {
username: username,
email: `${username}@example.com`,
first_name: username,
last_name: 'DiscordUser',
password: 'some-secure-password'
}, {
headers: {
'Authorization': `Bearer ${PTERO_API_KEY}`,
'Content-Type': 'application/json',
'Accept': 'application/json'
}
});

const pterodactylUserId = response.data.attributes.id;

await pool.query('INSERT INTO users (discord_id, username, pterodactyl_id) VALUES (?, ?, ?)', [discordId, username, pterodactylUserId]);

await interaction.reply(`User ${username} created successfully!`);
} catch (error) {
console.error(error);
await interaction.reply('There was an error creating the user. Please try again later.');
}
},
};
const { SlashCommandBuilder } = require('discord.js');
const mysql = require('mysql2/promise');
const axios = require('axios');

const pool = mysql.createPool({
host: 'your-database-host',
user: 'your-database-user',
password: 'your-database-password',
database: 'your-database-name'
});

const PTERO_API_URL = 'https://pterodactyl-instance.com/api/application';
const PTERO_API_KEY = 'pterodactyl-api-key';

module.exports = {
name: 'register',
description: 'Register a user for the server',

async execute(interaction) {
const discordId = interaction.user.id;
const username = interaction.user.username;

try {
const [rows] = await pool.query('SELECT * FROM users WHERE discord_id = ?', [discordId]);

if (rows.length > 0) {
await interaction.reply(`User with Discord ID ${discordId} already exists!`);
return;
}

const response = await axios.post(`${PTERO_API_URL}/users`, {
username: username,
email: `${username}@example.com`,
first_name: username,
last_name: 'DiscordUser',
password: 'some-secure-password'
}, {
headers: {
'Authorization': `Bearer ${PTERO_API_KEY}`,
'Content-Type': 'application/json',
'Accept': 'application/json'
}
});

const pterodactylUserId = response.data.attributes.id;

await pool.query('INSERT INTO users (discord_id, username, pterodactyl_id) VALUES (?, ?, ?)', [discordId, username, pterodactylUserId]);

await interaction.reply(`User ${username} created successfully!`);
} catch (error) {
console.error(error);
await interaction.reply('There was an error creating the user. Please try again later.');
}
},
};
I get: There was an error running this command: TypeError: commandObject.callback is not a function. Why is that?
3 Replies
d.js toolkit
d.js toolkit9mo 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! - Marked as resolved by OP
monbrey
monbrey9mo ago
Because your function is called execute, not callback
GustyCube
GustyCubeOP9mo ago
im so stupid lol

Did you find this page helpful?