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 toolkit10mo 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
ShompiFlen10mo ago
what is the error
vekizxo
vekizxoOP10mo ago
No description
ShompiFlen
ShompiFlen10mo 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?
vekizxo
vekizxoOP10mo ago
There is no error in the console, the bot just doesn’t respond
ShompiFlen
ShompiFlen10mo 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
vekizxo
vekizxoOP10mo ago
what does it mean i do not understand
ShompiFlen
ShompiFlen10mo 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
vekizxo
vekizxoOP10mo ago
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
vekizxo
vekizxoOP10mo ago
discord.js Guide
Imagine a guide... that explores the many possibilities for your discord.js bot.
ShompiFlen
ShompiFlen10mo ago
show your main script
vekizxo
vekizxoOP10mo ago
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
ShompiFlen10mo 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
vekizxo
vekizxoOP10mo ago
No description
vekizxo
vekizxoOP10mo ago
this code when I run main.js it also gives a good response
ShompiFlen
ShompiFlen10mo ago
thats the deploy script im talking about running your bot then doing /ban so it errors and gets logged to the console
vekizxo
vekizxoOP10mo ago
No description
ShompiFlen
ShompiFlen10mo ago
alright now trigger the command do /ban
vekizxo
vekizxoOP10mo ago
the application is not responding:Thonkang: wow now again "There was an error while executing this command! "
ShompiFlen
ShompiFlen10mo ago
okay and the console?
vekizxo
vekizxoOP10mo ago
kin.ts
kin.ts10mo ago
- await interaction.reply({embed});
+ await interaction.reply({ embeds: [embed] });
- await interaction.reply({embed});
+ await interaction.reply({ embeds: [embed] });
ShompiFlen
ShompiFlen10mo 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
vekizxo
vekizxoOP10mo ago
only if you delete this text, it work
ShompiFlen
ShompiFlen10mo ago
it shouldn't really work if you didn't fix what kin also said
vekizxo
vekizxoOP10mo ago
why?
ShompiFlen
ShompiFlen10mo 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
vekizxo
vekizxoOP10mo ago
but i use .setImage(${interaction.user.displayAvatarURL}) inside embed
ShompiFlen
ShompiFlen10mo ago
that is not what im talking about but anyway, if it works now then there you go
vekizxo
vekizxoOP10mo ago
await interaction.reply({ embeds: [embed] }); i did anyway error
kin.ts
kin.ts10mo ago
show it
vekizxo
vekizxoOP10mo ago
error?
kin.ts
kin.ts10mo ago
yea
vekizxo
vekizxoOP10mo ago
d.js docs
d.js docs10mo 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
ShompiFlen10mo 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
vekizxo
vekizxoOP10mo ago
so?
ShompiFlen
ShompiFlen10mo ago
show your code again your ban script
vekizxo
vekizxoOP10mo ago
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
ShompiFlen10mo ago
its a method you have to call it
vekizxo
vekizxoOP10mo ago
fine all work thanks
Want results from more Discord servers?
Add your server