where is the error

const { SlashCommandBuilder, PermissionFlagsBits, Client } = require('discord.js');
const { EmbedBuilder } = require('discord.js');

module.exports = {
data: new SlashCommandBuilder()
.setName('ban')
.setDescription('Ban user'),
async execute(interaction) {
new EmbedBuilder()
.setColor('#0099ff')
.setTitle(`${interaction.user.username}`)
.setDescription(`Ban: ...`)
.setImage(`${interaction.user.avatar}`)
.setTimestamp()
await interaction.reply({embed});
}
}
const { SlashCommandBuilder, PermissionFlagsBits, Client } = require('discord.js');
const { EmbedBuilder } = require('discord.js');

module.exports = {
data: new SlashCommandBuilder()
.setName('ban')
.setDescription('Ban user'),
async execute(interaction) {
new EmbedBuilder()
.setColor('#0099ff')
.setTitle(`${interaction.user.username}`)
.setDescription(`Ban: ...`)
.setImage(`${interaction.user.avatar}`)
.setTimestamp()
await interaction.reply({embed});
}
}
42 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! - Marked as resolved by staff
ShompiFlen
ShompiFlen3mo ago
what is the error
ShompiFlen
ShompiFlen3mo ago
okay so you are handling the error, that doesnt really help, can you show the code where that string is sent? check in your ban command script you are handling the error but are you printing it to the console?
уже не проверка мaindRRrreda
There is no error in the console, the bot just doesn’t respond
ShompiFlen
ShompiFlen3mo ago
look into your ban script send it if you can, its failing somewhere there. if you are using a try catch then log the error to the console, dont ignore it
уже не проверка мaindRRrreda
what does it mean i do not understand
ShompiFlen
ShompiFlen3mo ago
I can't help you if you are not providing any code debugging is a fundamental part of programming, also you have to understand your code, im telling you that somewhere in your ban command script or whatever code you execute when the command code is ran is throwing an error apparently you are handling that error in your code because the bot is actually replying, but its not executing the command. If the console doesn't log anything when this happens that means you are not logging the error wherever you are handling it that is as much as I can help without seeing any of your code
уже не проверка мaindRRrreda
const { SlashCommandBuilder, PermissionFlagsBits, Client } = require('discord.js');
const { EmbedBuilder } = require('discord.js');

module.exports = {
data: new SlashCommandBuilder()
.setName('ban')
.setDescription('Ban user'),
async execute(interaction) {
let embed = new EmbedBuilder()
.setColor('#0099ff')
.setTitle(`${interaction.user.username}`)
.setDescription(`Ban: ...`)
.setImage(`${interaction.user.avatar}`)
.setTimestamp()
await interaction.reply({embed});
}
}
const { SlashCommandBuilder, PermissionFlagsBits, Client } = require('discord.js');
const { EmbedBuilder } = require('discord.js');

module.exports = {
data: new SlashCommandBuilder()
.setName('ban')
.setDescription('Ban user'),
async execute(interaction) {
let embed = new EmbedBuilder()
.setColor('#0099ff')
.setTitle(`${interaction.user.username}`)
.setDescription(`Ban: ...`)
.setImage(`${interaction.user.avatar}`)
.setTimestamp()
await interaction.reply({embed});
}
}
its full code ban script alone start
уже не проверка мaindRRrreda
discord.js Guide
Imagine a guide... that explores the many possibilities for your discord.js bot.
ShompiFlen
ShompiFlen3mo ago
show your main script
уже не проверка мaindRRrreda
const fs = require('node:fs');
const path = require('node:path');
const { Client, Collection, Events, GatewayIntentBits } = require('discord.js');
const { token } = require('./config.json');

const client = new Client({ intents: [GatewayIntentBits.Guilds] });

client.commands = new Collection();

const foldersPath = path.join(__dirname, 'commands');
const commandFolders = fs.readdirSync(foldersPath);

for (const folder of commandFolders) {
const commandsPath = path.join(foldersPath, folder);
const commandFiles = fs.readdirSync(commandsPath).filter(file => file.endsWith('.js'));
for (const file of commandFiles) {
const filePath = path.join(commandsPath, file);
const command = require(filePath);
if ('data' in command && 'execute' in command) {
client.commands.set(command.data.name, command);
} else {
console.log(`[WARNING] The command at ${filePath} is missing a required "data" or "execute" property.`);
}
}
}

client.on(Events.InteractionCreate, interaction => {
console.log(interaction);
});

client.once(Events.ClientReady, readyClient => {
console.log(`Ready! Logged in as ${readyClient.user.tag}`);
});

client.on(Events.InteractionCreate, async interaction => {
if (!interaction.isChatInputCommand()) return;
const command = interaction.client.commands.get(interaction.commandName);

if (!command) {
console.error(`No command matching ${interaction.commandName} was found.`);
return;
}

try {
await command.execute(interaction);
} catch (error) {
console.error(error);
if (interaction.replied || interaction.deferred) {
await interaction.followUp({ content: 'There was an error while executing this command!', ephemeral: true });
} else {
await interaction.reply({ content: 'There was an error while executing this command!', ephemeral: true });
}
}
});

client.login(token);
const fs = require('node:fs');
const path = require('node:path');
const { Client, Collection, Events, GatewayIntentBits } = require('discord.js');
const { token } = require('./config.json');

const client = new Client({ intents: [GatewayIntentBits.Guilds] });

client.commands = new Collection();

const foldersPath = path.join(__dirname, 'commands');
const commandFolders = fs.readdirSync(foldersPath);

for (const folder of commandFolders) {
const commandsPath = path.join(foldersPath, folder);
const commandFiles = fs.readdirSync(commandsPath).filter(file => file.endsWith('.js'));
for (const file of commandFiles) {
const filePath = path.join(commandsPath, file);
const command = require(filePath);
if ('data' in command && 'execute' in command) {
client.commands.set(command.data.name, command);
} else {
console.log(`[WARNING] The command at ${filePath} is missing a required "data" or "execute" property.`);
}
}
}

client.on(Events.InteractionCreate, interaction => {
console.log(interaction);
});

client.once(Events.ClientReady, readyClient => {
console.log(`Ready! Logged in as ${readyClient.user.tag}`);
});

client.on(Events.InteractionCreate, async interaction => {
if (!interaction.isChatInputCommand()) return;
const command = interaction.client.commands.get(interaction.commandName);

if (!command) {
console.error(`No command matching ${interaction.commandName} was found.`);
return;
}

try {
await command.execute(interaction);
} catch (error) {
console.error(error);
if (interaction.replied || interaction.deferred) {
await interaction.followUp({ content: 'There was an error while executing this command!', ephemeral: true });
} else {
await interaction.reply({ content: 'There was an error while executing this command!', ephemeral: true });
}
}
});

client.login(token);
below is the moment that responds in case of command error
ShompiFlen
ShompiFlen3mo ago
yea although there is a console.error(error) there but you said nothing is getting logged to the console when the code throws the error are you sure about that trigger the command, if it errors then check the console copy and paste whatever shows up on it
уже не проверка мaindRRrreda
this code when I run main.js it also gives a good response
ShompiFlen
ShompiFlen3mo ago
thats the deploy script im talking about running your bot then doing /ban so it errors and gets logged to the console
ShompiFlen
ShompiFlen3mo ago
alright now trigger the command do /ban
уже не проверка мaindRRrreda
the application is not responding:Thonkang: wow now again "There was an error while executing this command! "
ShompiFlen
ShompiFlen3mo ago
okay and the console?
kin.ts
kin.ts3mo ago
- await interaction.reply({embed});
+ await interaction.reply({ embeds: [embed] });
- await interaction.reply({embed});
+ await interaction.reply({ embeds: [embed] });
ShompiFlen
ShompiFlen3mo ago
the error you are getting (aside from what kin said) is that you are passing an avatar hash to the embedBuilder.setImage() instead of an url use interaction.user.displayAvatarURL() instead to set the embed image
уже не проверка мaindRRrreda
only if you delete this text, it work
ShompiFlen
ShompiFlen3mo ago
it shouldn't really work if you didn't fix what kin also said
ShompiFlen
ShompiFlen3mo ago
because {embed} would make .send({embed: embedBuilder}) which would not send the embed with the message the property is embeds and it takes an array of embeds i mean Kin sent you the example
уже не проверка мaindRRrreda
but i use .setImage(${interaction.user.displayAvatarURL}) inside embed
ShompiFlen
ShompiFlen3mo ago
that is not what im talking about but anyway, if it works now then there you go
уже не проверка мaindRRrreda
await interaction.reply({ embeds: [embed] }); i did anyway error
kin.ts
kin.ts3mo ago
show it
kin.ts
kin.ts3mo ago
yea
d.js docs
d.js docs3mo ago
To share long code snippets, use a service like gist, sourcebin, starbin, or similar instead of posting them as large code blocks or files.
ShompiFlen
ShompiFlen3mo ago
it says you are passing this 'displayAvatarURL(options) {\n return this.avatarURL(options) ?? this.defaultAvatarURL;\n }' entire thing to setImage what did you change in your code
ShompiFlen
ShompiFlen3mo ago
show your code again your ban script
уже не проверка мaindRRrreda
const { SlashCommandBuilder, PermissionFlagsBits, Client } = require('discord.js');
const { EmbedBuilder } = require('discord.js');

module.exports = {
data: new SlashCommandBuilder()
.setName('ban')
.setDescription('Ban user'),
async execute(interaction) {
let embed = new EmbedBuilder()
.setColor('#0099ff')
.setTitle(`${interaction.user.username}`)
.setDescription(`Ban: ...`)
.setImage(`${interaction.user.displayAvatarURL}`)
.setTimestamp()
await interaction.reply({ embeds: [embed] });
}
}
const { SlashCommandBuilder, PermissionFlagsBits, Client } = require('discord.js');
const { EmbedBuilder } = require('discord.js');

module.exports = {
data: new SlashCommandBuilder()
.setName('ban')
.setDescription('Ban user'),
async execute(interaction) {
let embed = new EmbedBuilder()
.setColor('#0099ff')
.setTitle(`${interaction.user.username}`)
.setDescription(`Ban: ...`)
.setImage(`${interaction.user.displayAvatarURL}`)
.setTimestamp()
await interaction.reply({ embeds: [embed] });
}
}
ShompiFlen
ShompiFlen3mo ago
its a method you have to call it
уже не проверка мaindRRrreda
fine all work thanks