Bot stuck on thinking

here is my code:
const {
Client,
Interaction,
ApplicationCommandOptionType,
PermissionFlagsBits,
} = require('discord.js');
const fs = require('fs').promises;

module.exports = {
/**
*
* @param {Client} client
* @param {Interaction} interaction
*/
callback: async (client, interaction) => {
const channel = interaction.options.getChannel('channel');
const amount = interaction.options.getInteger('amount') || 0;
const channelId = channel.id;

await interaction.deferReply();

try {
// Read the existing data
const data = await fs.readFile('data.json', 'utf8');
const jsonData = JSON.parse(data);

// Add new channel entry
jsonData.channels.push({
channelID: channelId,
categories: {
resting: {
amount: 0
},
stock: {
amount: 0
}
}
});

// Write updated data back to file
await fs.writeFile('data.json', JSON.stringify(jsonData, null, 2));

await interaction.editReply(`New channel with ID ${channelId} created with stock amount set to ${amount}.`);
} catch (err) {
console.error('Error processing data file:', err);
await interaction.editReply('There was an error processing the data file.');
}
},

name: 'create',
description: 'Set the stock',
options: [
{
name: 'channel',
description: 'The channel to create or update.',
type: ApplicationCommandOptionType.Channel,
required: true,
},
],
permissionsRequired: [PermissionFlagsBits.ManageChannels],
};
const {
Client,
Interaction,
ApplicationCommandOptionType,
PermissionFlagsBits,
} = require('discord.js');
const fs = require('fs').promises;

module.exports = {
/**
*
* @param {Client} client
* @param {Interaction} interaction
*/
callback: async (client, interaction) => {
const channel = interaction.options.getChannel('channel');
const amount = interaction.options.getInteger('amount') || 0;
const channelId = channel.id;

await interaction.deferReply();

try {
// Read the existing data
const data = await fs.readFile('data.json', 'utf8');
const jsonData = JSON.parse(data);

// Add new channel entry
jsonData.channels.push({
channelID: channelId,
categories: {
resting: {
amount: 0
},
stock: {
amount: 0
}
}
});

// Write updated data back to file
await fs.writeFile('data.json', JSON.stringify(jsonData, null, 2));

await interaction.editReply(`New channel with ID ${channelId} created with stock amount set to ${amount}.`);
} catch (err) {
console.error('Error processing data file:', err);
await interaction.editReply('There was an error processing the data file.');
}
},

name: 'create',
description: 'Set the stock',
options: [
{
name: 'channel',
description: 'The channel to create or update.',
type: ApplicationCommandOptionType.Channel,
required: true,
},
],
permissionsRequired: [PermissionFlagsBits.ManageChannels],
};
the bot is just stuck on thinking...
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!
d.js docs
d.js docs6mo ago
If you aren't getting any errors, try to place console.log checkpoints throughout your code to find out where execution stops. - Once you do, log relevant values and if-conditions - More sophisticated debugging methods are breakpoints and runtime inspections: learn more
Want results from more Discord servers?
Add your server