is there any error or wrong formatting that would stop my bot from responding to commands
has all intents and also full permissions required but still no response to commands
very new to codeing a bot so trying to learn what i can but specific features i need some help to grasp
const Discord = require('discord.js');
const fs = require('fs');
const https = require('https');
const { EmbedBuilder } = require('discord.js');
const { ButtonBuilder } = require('discord.js')
const { ActionRowBuilder } = require('discord.js')
const { Client, IntentsBitField } = require('discord.js');
const client = new Client({
intents: [
IntentsBitField.Flags.Guilds,
IntentsBitField.Flags.GuildMembers,
IntentsBitField.Flags.GuildMessages,
IntentsBitField.Flags.MessageContent,
],
});
const PREFIX = '%';
client.on('ready', () => {
console.log(`Logged in as ${client.user.tag}!`);
});
client.on('message', async message => {
if (!message.content.startsWith(prefix) || message.author.bot) return;
const args = message.content.slice(prefix.length).trim().split(/ +/);
const command = args.shift().toLowerCase();
if (command === 'upload' && args.length === 2) {
const [initDataFile, jsonObjectFile] = args;
// Handle init.data file
if (!initDataFile.endsWith('.data')) {
return message.reply('Please upload a DayZ init.data file.');
}
const initFile = await message.attachments.find(
attachment => attachment.name.endsWith('.data')
);
if (!initFile) {
return message.reply('Please upload a DayZ init.data file.');
}
// Handle JSON object file
if (!jsonObjectFile.endsWith('.json')) {
return message.reply('Please upload a JSON file.');
}
const jsonObject = await message.attachments.find(
attachment => attachment.name.endsWith('.json')
);
if (!jsonObject) {
return message.reply('Please upload a JSON file.');
}
try {
const cleanedInitData = await cleanInitData(initFile);
const cleanedJsonObject = await cleanJsonObject(jsonObject);
const objectsJson = await convertToObjectsJson(cleanedInitData, cleanedJsonObject);
const messageStrings = [
'Here is your cleaned and converted Objects.json file:',
'```json',
objectsJson,
'```'
];
await message.author.send(messageStrings.join('n'));
} catch (error) {
console.error(error);
await message.reply('An error occurred while processing your files. Please try again later.');
}
}
});
// Define a check and replace list
const checkReplaceMap = {
"bldr_rock_bright_apart2": "DZ\rocks\rock_apart2.p3d"
};
const checkReplaceList = Object.keys(checkReplaceMap);
async function cleanInitData(initFile) {
const dirtyData = await initFile.attachment.download();
let cleanData = dirtyData
.replace(/SpawnObject("/g, "")
.replace(/",/g, " ")
.replace(/;/g, "")
.replace(/)/g, "")
.replace(/"/g, "")
.replace(/ /g, ' ');
for (const [key, value] of Object.entries(checkReplaceMap)) {
const regex = new RegExp(`(^|\s)${key}($|\s)`, 'g');
cleanData = cleanData.replace(regex, `$1${value}$2`);
}
return cleanData;
}
async function cleanJsonObject(jsonObject) {
const jsonString = await jsonObject.attachment.download();
let cleanJsonString = jsonString;
for (const [key, value] of Object.entries(checkReplaceMap)) {
const regex = new RegExp(`(^|\s)${key}($|\s)`, 'g');
cleanJsonString = cleanJsonString.replace(regex, `$1${value}$2`);
}
return JSON.parse(cleanJsonString);
}
function convertToObjectsJson(initData, jsonObject) {
const lines = initData.split('n');
const objects = lines.map(line => {
const [name, pos, ypr, scale] = line.split(/[(),"]/).slice(1, -1).map(str => str.trim());
const [x, y, z] = pos.split(/s+/).map(str => Number(str));
const [pitch, yaw, roll] = ypr.split(/s+/).map(str => Number(str));
return {
name,
pos: [x, y, z],
ypr: [-pitch, yaw, roll],
scale: Number(scale)
};
});
jsonObject.Objects = objects;
return JSON.stringify(jsonObject, null, 2);
}
client.login('TOKEN_HEAR');
is there any error or wrong formatting that would stop my bot from responding to commands
has all intents and also full permissions required but still no response to commands
very new to codeing a bot so trying to learn what i can but specific features i need some help to grasp
the bot will basically use a ckeck replace list of names when a user uploads the init.c or json game file it will search for any match and replace the names in the uploaded file then return the data back to the user in .json set out for dayz objectspawner.json

