I wanted to write a code that will send an embed with all the commands so I wrote a code that works but after sending the embed it shows an error above the embed: embed. Here's the code:
const { Client, GatewayIntentBits, CommandInteraction, EmbedBuilder } = require('discord.js')
const client = new Client({
intents: [
GatewayIntentBits.Guilds,
// ...
]
});
client.on('ready', async () => {
console.log(`Logged in as ${client.user.tag}!`);
const commands = [
{
name: 'pomoc',
description: 'Wyświetla wszystkie komendy'
}
];
const commandData = commands.map(command => ({
name: command.name,
description: command.description
}));
const commandManager = await client.application?.commands.set(commandData);
console.log(`Registered ${commandManager.size} slash commands`);
});
client.on('interactionCreate', interaction => {
if (!interaction.isCommand()) return;
if (interaction.commandName === 'pomoc') {
const embed = new EmbedBuilder()
.setTitle('some title')
.setDescription('some description')
interaction.channel.send({embeds: [embed]})
}
});
client.login(process.env.CLIENT_TOKEN);
I tried this method:
interaction.channel.send({
embeds: [{
title: 'some title',
description: 'some description',
image: {url: 'image url'}
}]
})
The issue is that you're sending a message in the interaction channel, rather than replying to the interaction itself.
Upon calling a slash command, discord will send a request to your server and await a response. This error is due to the response timing out, as your server makes a separate request rather than responding to the initial request.
Rather than using interaction.channel.send(details)
, you should be using interaction.reply(details)
to respond to the interaction.