You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Here's the code I am working with:
const { Client, Intents } = require('discord.js');
const node = require('jspteroapi');
const client = new Client({
intents: [Intents.FLAGS.GUILDS, Intents.FLAGS.GUILD_MESSAGES],
});
const host = 'X';
const apiKey = 'x';
const application = new node.Application(host, apiKey);
const allowedChannelId = 'x'; // Replace with your desired channel ID
async function deleteServerAndUser(serverId) {
try {
console.log(Fetching server information for ID ${serverId});
const serverInfo = await application.getServerInfo(serverId);
console.log('Server Information:', serverInfo);
const ownerId = serverInfo.user;
console.log(`User extracted from serverInfo: ${ownerId}`);
console.log(`Deleting server with ID ${serverId}`);
const deleteServerRes = await application.deleteServer(serverId);
console.log(deleteServerRes)
if (deleteServerRes.headers['content-type'].includes('json')) {
console.log(`Server deletion successful.`);
} else {
console.log(`Server deletion failed. Unexpected response format.`);
}
console.log(`Deleting user with ID ${ownerId}`);
const deleteUserRes = await application.deleteUser(ownerId);
console.log('User deletion response:', deleteUserRes.data);
if (deleteUserRes.headers['content-type'].includes('json')) {
console.log(`User deletion successful.`);
} else {
console.log(`User deletion failed. Unexpected response format.`);
}
// Return user information
return { user: ownerId };
} catch (error) {
console.error(Error deleting server and user for ID ${serverId}: ${error.message});
throw error;
}
}
const serverId = message.content.trim();
if (!serverId || isNaN(serverId)) return;
const serverIdInt = parseInt(serverId, 10); // Convert to integer
console.log(`Received command to delete server and user for ID ${serverIdInt}`);
const extractRes = await deleteServerAndUser(serverIdInt);
console.log(`User and server deleted for ID ${serverIdInt}`, extractRes);
message.channel.send(`User and server deleted for ID ${serverIdInt}`);
} catch (error) {
console.error(Error: ${error.message});
message.channel.send(Error: ${error.message});
}
});
client.on('ready', () => {
console.log('Bot is now connected and ready.');
});
Here's the code I am working with:
const { Client, Intents } = require('discord.js');
const node = require('jspteroapi');
const client = new Client({
intents: [Intents.FLAGS.GUILDS, Intents.FLAGS.GUILD_MESSAGES],
});
const host = 'X';
const apiKey = 'x';
const application = new node.Application(host, apiKey);
const allowedChannelId = 'x'; // Replace with your desired channel ID
async function deleteServerAndUser(serverId) {
try {
console.log(
Fetching server information for ID ${serverId}
);const serverInfo = await application.getServerInfo(serverId);
console.log('Server Information:', serverInfo);
} catch (error) {
console.error(
Error deleting server and user for ID ${serverId}: ${error.message}
);throw error;
}
}
client.on('messageCreate', async (message) => {
try {
if (message.author.bot || message.channel.id !== allowedChannelId) return;
} catch (error) {
console.error(
Error: ${error.message}
);message.channel.send(
Error: ${error.message}
);}
});
client.on('ready', () => {
console.log('Bot is now connected and ready.');
});
client.on('error', (error) => {
console.error('Discord client error:', error.message);
});
client.login(' X ');
And here's the response:
Bot is now connected and ready.
Received command to delete server and user for ID 6771
Fetching server information for ID 6771
Server Information: {
id: 6771,
external_id: null,
uuid: '192dbb51-afc9-4d58-bfb4-70a9f44c3fa9',
identifier: '192dbb51',
name: 'ew',
description: '',
status: null,
suspended: false,
limits: {
memory: 0,
swap: 0,
disk: 0,
io: 500,
cpu: 0,
threads: null,
oom_disabled: true
},
feature_limits: { databases: 0, allocations: 0, backups: 0 },
user: 4538,
node: 6,
allocation: 394,
nest: 1,
egg: 1,
container: {
startup_command: 'java -Xms128M -XX:MaxRAMPercentage=95.0 -Dterminal.jline=false -Dterminal.ansi=true -jar {{SERVER_JARFILE}}',
image: 'ghcr.io/pterodactyl/yolks:java_17',
installed: 1,
environment: {
MINECRAFT_VERSION: 'latest',
SERVER_JARFILE: 'server.jar',
DL_PATH: '',
BUILD_NUMBER: 'latest',
STARTUP: 'java -Xms128M -XX:MaxRAMPercentage=95.0 -Dterminal.jline=false -Dterminal.ansi=true -jar {{SERVER_JARFILE}}',
P_SERVER_LOCATION: 'Germany',
P_SERVER_UUID: '192dbb51-afc9-4d58-bfb4-70a9f44c3fa9',
P_SERVER_ALLOCATION_LIMIT: 0
}
},
updated_at: '2024-01-27T14:20:13+00:00',
created_at: '2024-01-27T14:20:09+00:00'
}
User extracted from serverInfo: 4538
Deleting server with ID 6771
Error deleting server and user for ID 6771: Unexpected token '<', "<!DOCTYPE "... is not valid JSON
Error: Unexpected token '<', "<!DOCTYPE "... is not valid JSON
I don't knows what's wrong with it and why it expects JSON.
The text was updated successfully, but these errors were encountered: