Aplication doesn't respond

Hi ! I have a problem under dJS 14 When I execute a command / the bot responds to me the application no longer responds even though I haven't touched the code since and it works very well I have no console error and I use everything in command handler I send the code here ? sorry my English is not perfect I am a desperate Frenchman
15 Replies
d.js toolkit
d.js toolkit3mo 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 docs3mo 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
Artix.
Artix.OP3mo ago
[email protected] v20.16.0
const { Client, GatewayIntentBits, Collection, REST, Routes, EmbedBuilder } = require('discord.js');
const fs = require('fs');
const path = require('path');
const { token, clientId, guildId, starboardChannelId } = require('./config.json');

// Création du client Discord
const client = new Client({
intents: [
GatewayIntentBits.Guilds,
GatewayIntentBits.GuildMessages,
GatewayIntentBits.MessageContent,
GatewayIntentBits.GuildMessageReactions,
GatewayIntentBits.GuildMembers,
GatewayIntentBits.GuildPresences,
]
});

client.commands = new Collection();

const commandsPath = path.join(__dirname, 'commands');
const commandFiles = fs.readdirSync(commandsPath).filter(file => file.endsWith('.js'));

const commands = [];

for (const file of commandFiles) {
const filePath = path.join(commandsPath, file);
const command = require(filePath);
client.commands.set(command.data.name, command);
commands.push(command.data.toJSON());
}

// Fonction pour déployer les commandes
const deployCommands = async () => {
const rest = new REST({ version: '10' }).setToken(token);
try {
console.log('Déploiement des commandes en cours...');

if (guildId) {
await rest.put(
Routes.applicationGuildCommands(clientId, guildId),
{ body: commands },
);
console.log('Commandes spécifiques au serveur déployées avec succès.');
console.log(`Commandes chargées : ${client.commands.map(cmd => cmd.data.name).join(', ')}`);
} else {
await rest.put(
Routes.applicationCommands(clientId),
{ body: commands },
);
console.log('Commandes globales déployées avec succès.');
}
} catch (error) {
console.error('Erreur lors du déploiement des commandes :', error);
}
};

client.once('ready', async () => {
console.log(`Bot connecté en tant que ${client.user.tag}`);
await deployCommands();
});
const { Client, GatewayIntentBits, Collection, REST, Routes, EmbedBuilder } = require('discord.js');
const fs = require('fs');
const path = require('path');
const { token, clientId, guildId, starboardChannelId } = require('./config.json');

// Création du client Discord
const client = new Client({
intents: [
GatewayIntentBits.Guilds,
GatewayIntentBits.GuildMessages,
GatewayIntentBits.MessageContent,
GatewayIntentBits.GuildMessageReactions,
GatewayIntentBits.GuildMembers,
GatewayIntentBits.GuildPresences,
]
});

client.commands = new Collection();

const commandsPath = path.join(__dirname, 'commands');
const commandFiles = fs.readdirSync(commandsPath).filter(file => file.endsWith('.js'));

const commands = [];

for (const file of commandFiles) {
const filePath = path.join(commandsPath, file);
const command = require(filePath);
client.commands.set(command.data.name, command);
commands.push(command.data.toJSON());
}

// Fonction pour déployer les commandes
const deployCommands = async () => {
const rest = new REST({ version: '10' }).setToken(token);
try {
console.log('Déploiement des commandes en cours...');

if (guildId) {
await rest.put(
Routes.applicationGuildCommands(clientId, guildId),
{ body: commands },
);
console.log('Commandes spécifiques au serveur déployées avec succès.');
console.log(`Commandes chargées : ${client.commands.map(cmd => cmd.data.name).join(', ')}`);
} else {
await rest.put(
Routes.applicationCommands(clientId),
{ body: commands },
);
console.log('Commandes globales déployées avec succès.');
}
} catch (error) {
console.error('Erreur lors du déploiement des commandes :', error);
}
};

client.once('ready', async () => {
console.log(`Bot connecté en tant que ${client.user.tag}`);
await deployCommands();
});
// STARBOARD

client.on('messageReactionAdd', async (reaction, user) => {
if (reaction.partial) await reaction.fetch();
if (user.bot) return;

const { message } = reaction;

if (user.id === message.author.id && reaction.emoji.name === '⭐') {
return await reaction.users.remove(user.id);
}

if (reaction.emoji.name === '⭐' && reaction.count >= 3) {
const starboardChannel = client.channels.cache.get(starboardChannelId);
if (!starboardChannel) return console.log('Channel introuvable.');

const messageLink = `https://discord.com/channels/${message.guild.id}/${message.channel.id}/${message.id}`;

const embed = new EmbedBuilder()
.setColor('#FFD700')
.setAuthor({ name: "⭐ Starboard ⭐ " + "@" + message.author.tag, iconURL: message.author.displayAvatarURL() })
.setDescription(`${message.content || 'Aucun message.'}\n\n[➡️ Message original](${messageLink})`)
.setTimestamp(message.createdTimestamp)
.setFooter({ text: `⭐ ${reaction.count} | Message ID: ${message.id}` });

if (message.attachments.size > 0) {
const attachment = message.attachments.first();
if (attachment.contentType.startsWith('image/')) {
embed.setImage(attachment.url);
}
}

await starboardChannel.send({ embeds: [embed] });
}
});

// Suppression lien discord

client.on('messageCreate', async (message) => {
if (message.author.bot) return;

const inviteRegex = /discord\.gg\/\w+|discordapp\.com\/invite\/\w+/i;

if (inviteRegex.test(message.content)) {
try {
await message.delete();

const warnsFilePath = path.join(__dirname, 'warns.json');
const warnsData = fs.existsSync(warnsFilePath) ? JSON.parse(fs.readFileSync(warnsFilePath, 'utf8')) : {};

const userId = message.author.id;
if (!warnsData[userId]) {
warnsData[userId] = [];
}
const newWarnId = warnsData[userId].length + 1;

warnsData[userId].push({
id: newWarnId,
reason: 'Lien discord',
timestamp: new Date().toISOString(),
messageContent: message.content
});

fs.writeFileSync(warnsFilePath, JSON.stringify(warnsData, null, 2));

console.log(`Warn ajouté ${message.author.tag} ID: ${newWarnId}`);
} catch (error) {
console.error('Erreur:', error);
}
}
});

client.login(token);
// STARBOARD

client.on('messageReactionAdd', async (reaction, user) => {
if (reaction.partial) await reaction.fetch();
if (user.bot) return;

const { message } = reaction;

if (user.id === message.author.id && reaction.emoji.name === '⭐') {
return await reaction.users.remove(user.id);
}

if (reaction.emoji.name === '⭐' && reaction.count >= 3) {
const starboardChannel = client.channels.cache.get(starboardChannelId);
if (!starboardChannel) return console.log('Channel introuvable.');

const messageLink = `https://discord.com/channels/${message.guild.id}/${message.channel.id}/${message.id}`;

const embed = new EmbedBuilder()
.setColor('#FFD700')
.setAuthor({ name: "⭐ Starboard ⭐ " + "@" + message.author.tag, iconURL: message.author.displayAvatarURL() })
.setDescription(`${message.content || 'Aucun message.'}\n\n[➡️ Message original](${messageLink})`)
.setTimestamp(message.createdTimestamp)
.setFooter({ text: `⭐ ${reaction.count} | Message ID: ${message.id}` });

if (message.attachments.size > 0) {
const attachment = message.attachments.first();
if (attachment.contentType.startsWith('image/')) {
embed.setImage(attachment.url);
}
}

await starboardChannel.send({ embeds: [embed] });
}
});

// Suppression lien discord

client.on('messageCreate', async (message) => {
if (message.author.bot) return;

const inviteRegex = /discord\.gg\/\w+|discordapp\.com\/invite\/\w+/i;

if (inviteRegex.test(message.content)) {
try {
await message.delete();

const warnsFilePath = path.join(__dirname, 'warns.json');
const warnsData = fs.existsSync(warnsFilePath) ? JSON.parse(fs.readFileSync(warnsFilePath, 'utf8')) : {};

const userId = message.author.id;
if (!warnsData[userId]) {
warnsData[userId] = [];
}
const newWarnId = warnsData[userId].length + 1;

warnsData[userId].push({
id: newWarnId,
reason: 'Lien discord',
timestamp: new Date().toISOString(),
messageContent: message.content
});

fs.writeFileSync(warnsFilePath, JSON.stringify(warnsData, null, 2));

console.log(`Warn ajouté ${message.author.tag} ID: ${newWarnId}`);
} catch (error) {
console.error('Erreur:', error);
}
}
});

client.login(token);
My index.js
treble/luna
treble/luna3mo ago
do this and dont deploy your commands upon ready only when you edit them
Artix.
Artix.OP3mo ago
hmmm ok
treble/luna
treble/luna3mo ago
i also dont see where you are actually handling your commands
Artix.
Artix.OP3mo ago
how so ?
treble/luna
treble/luna3mo ago
because i dont see any interactionCreate event listener
Artix.
Artix.OP3mo ago
here
client.commands = new Collection();

const commandsPath = path.join(__dirname, 'commands');
const commandFiles = fs.readdirSync(commandsPath).filter(file => file.endsWith('.js'));

const commands = [];

for (const file of commandFiles) {
const filePath = path.join(commandsPath, file);
const command = require(filePath);
client.commands.set(command.data.name, command);
commands.push(command.data.toJSON());
}

// Fonction pour déployer les commandes
const deployCommands = async () => {
const rest = new REST({ version: '10' }).setToken(token);
try {
console.log('Déploiement des commandes en cours...');

if (guildId) {
await rest.put(
Routes.applicationGuildCommands(clientId, guildId),
{ body: commands },
);
console.log('Commandes spécifiques au serveur déployées avec succès.');
console.log(`Commandes chargées : ${client.commands.map(cmd => cmd.data.name).join(', ')}`);
} else {
await rest.put(
Routes.applicationCommands(clientId),
{ body: commands },
);
console.log('Commandes globales déployées avec succès.');
}
} catch (error) {
console.error('Erreur lors du déploiement des commandes :', error);
}
};
client.commands = new Collection();

const commandsPath = path.join(__dirname, 'commands');
const commandFiles = fs.readdirSync(commandsPath).filter(file => file.endsWith('.js'));

const commands = [];

for (const file of commandFiles) {
const filePath = path.join(commandsPath, file);
const command = require(filePath);
client.commands.set(command.data.name, command);
commands.push(command.data.toJSON());
}

// Fonction pour déployer les commandes
const deployCommands = async () => {
const rest = new REST({ version: '10' }).setToken(token);
try {
console.log('Déploiement des commandes en cours...');

if (guildId) {
await rest.put(
Routes.applicationGuildCommands(clientId, guildId),
{ body: commands },
);
console.log('Commandes spécifiques au serveur déployées avec succès.');
console.log(`Commandes chargées : ${client.commands.map(cmd => cmd.data.name).join(', ')}`);
} else {
await rest.put(
Routes.applicationCommands(clientId),
{ body: commands },
);
console.log('Commandes globales déployées avec succès.');
}
} catch (error) {
console.error('Erreur lors du déploiement des commandes :', error);
}
};
All for my command collection
treble/luna
treble/luna3mo ago
that deploys your commands it doesnt handle them i highly doubt this worked perfectly if you dont even have an interactionCreate listener
Artix.
Artix.OP3mo ago
and yep yes I haven't used it interactionCreate but it works normally
treble/luna
treble/luna3mo ago
it does not
Artix.
Artix.OP3mo ago
Yesterday I didn't have the problem and I don't fully understand why.
treble/luna
treble/luna3mo ago
because you dont have any interactionCreate listeners
Artix.
Artix.OP3mo ago
hmmm I will listen to your advice I will try to work on it again its good thx
Want results from more Discord servers?
Add your server