Error with bot

Hey. I'm using the pterotacy; api: and I got this error:
AxiosError: Request failed with status code 422
at settle (C:\Users\Bennett\Downloads\GustyHostBot\GustyHostBot\node_modules\axios\dist\node\axios.cjs:1983:12)
at IncomingMessage.handleStreamEnd (C:\Users\Bennett\Downloads\GustyHostBot\GustyHostBot\node_modules\axios\dist\node\axios.cjs:3085:11)
at IncomingMessage.emit (node:events:531:35)
at endReadableNT (node:internal/streams/readable:1696:12)
at process.processTicksAndRejections (node:internal/process/task_queues:82:21)
at Axios.request (C:\Users\Bennett\Downloads\GustyHostBot\GustyHostBot\node_modules\axios\dist\node\axios.cjs:4224:41)
at process.processTicksAndRejections (node:internal/process/task_queues:95:5)
at async Object.callback (C:\Users\Bennett\Downloads\GustyHostBot\GustyHostBot\src\commands\servers\createAccount.js:38:24)
at async module.exports (C:\Users\Bennett\Downloads\GustyHostBot\GustyHostBot\src\events\interactionCreate\handleCommands.js:62:5)
at async Client.<anonymous> (C:\Users\Bennett\Downloads\GustyHostBot\GustyHostBot\src\handlers\eventHandler.js:16:9) {
code: 'ERR_BAD_REQUEST',
AxiosError: Request failed with status code 422
at settle (C:\Users\Bennett\Downloads\GustyHostBot\GustyHostBot\node_modules\axios\dist\node\axios.cjs:1983:12)
at IncomingMessage.handleStreamEnd (C:\Users\Bennett\Downloads\GustyHostBot\GustyHostBot\node_modules\axios\dist\node\axios.cjs:3085:11)
at IncomingMessage.emit (node:events:531:35)
at endReadableNT (node:internal/streams/readable:1696:12)
at process.processTicksAndRejections (node:internal/process/task_queues:82:21)
at Axios.request (C:\Users\Bennett\Downloads\GustyHostBot\GustyHostBot\node_modules\axios\dist\node\axios.cjs:4224:41)
at process.processTicksAndRejections (node:internal/process/task_queues:95:5)
at async Object.callback (C:\Users\Bennett\Downloads\GustyHostBot\GustyHostBot\src\commands\servers\createAccount.js:38:24)
at async module.exports (C:\Users\Bennett\Downloads\GustyHostBot\GustyHostBot\src\events\interactionCreate\handleCommands.js:62:5)
at async Client.<anonymous> (C:\Users\Bennett\Downloads\GustyHostBot\GustyHostBot\src\handlers\eventHandler.js:16:9) {
code: 'ERR_BAD_REQUEST',
with this code:
const { SlashCommandBuilder } = require('discord.js');
const mysql = require('mysql2/promise');
const axios = require('axios');

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

const PTERO_API_URL = 'https://URL/api/application/users';
const PTERO_API_KEY = '';

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

async callback(interaction) {
const discordId = interaction.user.id;
const username = "GustyCube";

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 password = Math.random().toString(36).slice(-8);

console.log(username

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

const pterodactylUserId = response.data.object.id;
print(pterodactylUserId)

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

await interaction.reply(`User ${username} created successfully! A temporary password has been generated. Please set a new password through the Pterodactyl panel for security reasons.`);
} catch (error) {
console.error(error);
if (error.response && error.response.status === 429) {
await interaction.reply('Rate limit reached. Please try again later.');
} else {
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: '',
user: '',
password: '',
database: ''
});

const PTERO_API_URL = 'https://URL/api/application/users';
const PTERO_API_KEY = '';

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

async callback(interaction) {
const discordId = interaction.user.id;
const username = "GustyCube";

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 password = Math.random().toString(36).slice(-8);

console.log(username

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

const pterodactylUserId = response.data.object.id;
print(pterodactylUserId)

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

await interaction.reply(`User ${username} created successfully! A temporary password has been generated. Please set a new password through the Pterodactyl panel for security reasons.`);
} catch (error) {
console.error(error);
if (error.response && error.response.status === 429) {
await interaction.reply('Rate limit reached. Please try again later.');
} else {
await interaction.reply('There was an error creating the user. Please try again later.');
}
}
},
};
Their documentation: https://dashflo.net/docs/api/pterodactyl/v1/#req_802e27a56fe142c99db4106d8e8e8892 You go to API/Application > /users > POST create user
hosted at dashflo.net
Pterodactyl v1 API Reference
The application and client API documentation for Pterodactyl v1, the free open-source server management solution. Easily do anything you normally can do with Pterodactyl's interface, just through the API.
2 Replies
d.js toolkit
d.js toolkit6mo 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!
monbrey
monbrey6mo ago
This is not a discord.js issue, the error is being thrown by axios which we do not use
Want results from more Discord servers?
Add your server