How can I log slash commands like this:

How can I log slash commands like this: Command: mute Content: member: @Member time: Time reason: Reason /mute member: @</Almaz> time: 60m reason: offtop Screenshot of my logging now:
No description
43 Replies
d.js toolkit
d.js toolkit9mo 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 OP
Булочка | pasha_boez
@</Almaz>You need to parse options. One of the way - use <ChatInputCommandInteraction>.options.map function
</> Almaz </>
</> Almaz </>9mo ago
не работает, брат хлеб An error occurred: Error: Received one or more errors @Булочка | pasha_boez прислать код?
Булочка | pasha_boez
#rules 2 😦 Yes, if you can
</> Almaz </>
</> Almaz </>9mo ago
const { ActionRowBuilder, ButtonBuilder, ButtonStyle, EmbedBuilder, InteractionType } = require("discord.js");

module.exports.run = async (client, interaction) => {
if (interaction.type === InteractionType.ApplicationCommand) {
const command = client.slashCommands.get(interaction.commandName);
try {
if (interaction.user.id !== '718458417232085104') {
const msg_cmd = [
`[SLASH] ${command.name}`,
`used by ${interaction.user.tag} from ${interaction.guild.name} (${interaction.guild.id})`,
];

console.log(`${msg_cmd.join(" ")}`);

const channelID = '1156275068209479680';
const specchannel = interaction.guild.channels.cache.get(channelID);

const content = interaction.options.data.map((option) => {
return `${option.name}: ${option.value}`;
}).join(' ');

const Embed = new EmbedBuilder()
.setTitle(`Была использована команда.`)
.setColor('#32a899')
.addFields([
{ name: `**Команда**:`, value: `**${command.name}**`, inline: true },
{ name: `**Содержание**:`, value: `${content}`, inline: true },
{ name: `**Пользователь**:`, value: `${interaction.user.tag}`, inline: true },
{ name: `**Сервер**:`, value: `**${interaction.guild.name}**`, inline: true },
{ name: `**ID сервера**:`, value: `${interaction.guild.id}`, inline: true },
])
.setTimestamp();

specchannel.send({ embeds: [Embed] });
}
} catch (error) {
console.error(`An error occurred: ${error}`);
}
const { ActionRowBuilder, ButtonBuilder, ButtonStyle, EmbedBuilder, InteractionType } = require("discord.js");

module.exports.run = async (client, interaction) => {
if (interaction.type === InteractionType.ApplicationCommand) {
const command = client.slashCommands.get(interaction.commandName);
try {
if (interaction.user.id !== '718458417232085104') {
const msg_cmd = [
`[SLASH] ${command.name}`,
`used by ${interaction.user.tag} from ${interaction.guild.name} (${interaction.guild.id})`,
];

console.log(`${msg_cmd.join(" ")}`);

const channelID = '1156275068209479680';
const specchannel = interaction.guild.channels.cache.get(channelID);

const content = interaction.options.data.map((option) => {
return `${option.name}: ${option.value}`;
}).join(' ');

const Embed = new EmbedBuilder()
.setTitle(`Была использована команда.`)
.setColor('#32a899')
.addFields([
{ name: `**Команда**:`, value: `**${command.name}**`, inline: true },
{ name: `**Содержание**:`, value: `${content}`, inline: true },
{ name: `**Пользователь**:`, value: `${interaction.user.tag}`, inline: true },
{ name: `**Сервер**:`, value: `**${interaction.guild.name}**`, inline: true },
{ name: `**ID сервера**:`, value: `${interaction.guild.id}`, inline: true },
])
.setTimestamp();

specchannel.send({ embeds: [Embed] });
}
} catch (error) {
console.error(`An error occurred: ${error}`);
}
little part
Булочка | pasha_boez
Send full text of error please
</> Almaz </>
</> Almaz </>9mo ago
An error occurred: Error: Received one or more errors it's full error
No description
Булочка | pasha_boez
Why you use options.data? Use just options.map
</> Almaz </>
</> Almaz </>9mo ago
same error
Булочка | pasha_boez
Type console.error(error) after catch. Don't stringify it My bad. Options.data it's true And send error from it
</> Almaz </>
</> Almaz </>9mo ago
?
No description
Булочка | pasha_boez
Yes @</Almaz>
</> Almaz </>
</> Almaz </>9mo ago
went to the toilet
Булочка | pasha_boez
Oh, sorry
</> Almaz </>
</> Almaz </>9mo ago
CombinedPropertyError (1)
Received one or more errors
input[1]
| CombinedPropertyError (1)
| Received one or more errors
|
| input.value
| | ExpectedConstraintError > s.string.lengthGreaterThanOrEqual
| | Invalid string length
| |
| | Expected: expected.length >= 1
| |
| | Received:
| | | ''
at ArrayValidator.handle (/home/container/node_modules/@sapphire/shapeshift/dist/index.js:473:70)
at ArrayValidator.parse (/home/container/node_modules/@sapphire/shapeshift/dist/index.js:212:88)
at EmbedBuilder.addFields (/home/container/node_modules/@discordjs/builders/dist/index.js:222:31)
at module.exports.run (/home/container/src/events/botEvents/guild/interactionCreate.js:45:8)
at process.processTicksAndRejections (node:internal/process/task_queues:95:5)
CombinedPropertyError (1)
Received one or more errors
input[1]
| CombinedPropertyError (1)
| Received one or more errors
|
| input.value
| | ExpectedConstraintError > s.string.lengthGreaterThanOrEqual
| | Invalid string length
| |
| | Expected: expected.length >= 1
| |
| | Received:
| | | ''
at ArrayValidator.handle (/home/container/node_modules/@sapphire/shapeshift/dist/index.js:473:70)
at ArrayValidator.parse (/home/container/node_modules/@sapphire/shapeshift/dist/index.js:212:88)
at EmbedBuilder.addFields (/home/container/node_modules/@discordjs/builders/dist/index.js:222:31)
at module.exports.run (/home/container/src/events/botEvents/guild/interactionCreate.js:45:8)
at process.processTicksAndRejections (node:internal/process/task_queues:95:5)
Булочка | pasha_boez
You use command with options?
</> Almaz </>
</> Almaz </>9mo ago
oh, no
</> Almaz </>
</> Almaz </>9mo ago
working, but what to do with other commands, without options
No description
Булочка | pasha_boez
You can remove twend field with <EmbedBuilder>.spliceFields, or just create other embed for <ChatInputCommandInteraction>.options.data.length === 0 @</Almaz>
</> Almaz </>
</> Almaz </>9mo ago
see
Булочка | pasha_boez
Also you can create embed without fields and add them after check for options length
</> Almaz </>
</> Almaz </>9mo ago
can you show? I don’t understand show where to put it
Булочка | pasha_boez
const { ActionRowBuilder, ButtonBuilder, ButtonStyle, EmbedBuilder, InteractionType } = require("discord.js");

module.exports.run = async (client, interaction) => {
if (interaction.type === InteractionType.ApplicationCommand) {
const command = client.slashCommands.get(interaction.commandName);
try {
if (interaction.user.id !== '718458417232085104') {
const msg_cmd = [
`[SLASH] ${command.name}`,
`used by ${interaction.user.tag} from ${interaction.guild.name} (${interaction.guild.id})`,
];

console.log(`${msg_cmd.join(" ")}`);
const { ActionRowBuilder, ButtonBuilder, ButtonStyle, EmbedBuilder, InteractionType } = require("discord.js");

module.exports.run = async (client, interaction) => {
if (interaction.type === InteractionType.ApplicationCommand) {
const command = client.slashCommands.get(interaction.commandName);
try {
if (interaction.user.id !== '718458417232085104') {
const msg_cmd = [
`[SLASH] ${command.name}`,
`used by ${interaction.user.tag} from ${interaction.guild.name} (${interaction.guild.id})`,
];

console.log(`${msg_cmd.join(" ")}`);
const channelID = '1156275068209479680';
const specchannel = interaction.guild.channels.cache.get(channelID);

const content = interaction.options.data.map((option) => {
return `${option.name}: ${option.value}`;
}).join(' ');

const Embed = new EmbedBuilder()
.setTitle(`Была использована команда.`)
.setColor('#32a899')
.setTimestamp();

if (interaction.options.data.length !== 0) Embed.addFields([
{ name: `**Команда**:`, value: `**${command.name}**`, inline: true },
{ name: `**Содержание**:`, value: `${content}`, inline: true },
{ name: `**Пользователь**:`, value: `${interaction.user.tag}`, inline: true },
{ name: `**Сервер**:`, value: `**${interaction.guild.name}**`, inline: true },
{ name: `**ID сервера**:`, value: `${interaction.guild.id}`, inline: true },
])
else Embed.addFields([
{ name: `**Команда**:`, value: `**${command.name}**`, inline: true },
{ name: `**Пользователь**:`, value: `${interaction.user.tag}`, inline: true },
{ name: `**Сервер**:`, value: `**${interaction.guild.name}**`, inline: true },
{ name: `**ID сервера**:`, value: `${interaction.guild.id}`, inline: true },
])

specchannel.send({ embeds: [Embed] });
}
} catch (error) {
console.error(`An error occurred: ${error}`);
}
const channelID = '1156275068209479680';
const specchannel = interaction.guild.channels.cache.get(channelID);

const content = interaction.options.data.map((option) => {
return `${option.name}: ${option.value}`;
}).join(' ');

const Embed = new EmbedBuilder()
.setTitle(`Была использована команда.`)
.setColor('#32a899')
.setTimestamp();

if (interaction.options.data.length !== 0) Embed.addFields([
{ name: `**Команда**:`, value: `**${command.name}**`, inline: true },
{ name: `**Содержание**:`, value: `${content}`, inline: true },
{ name: `**Пользователь**:`, value: `${interaction.user.tag}`, inline: true },
{ name: `**Сервер**:`, value: `**${interaction.guild.name}**`, inline: true },
{ name: `**ID сервера**:`, value: `${interaction.guild.id}`, inline: true },
])
else Embed.addFields([
{ name: `**Команда**:`, value: `**${command.name}**`, inline: true },
{ name: `**Пользователь**:`, value: `${interaction.user.tag}`, inline: true },
{ name: `**Сервер**:`, value: `**${interaction.guild.name}**`, inline: true },
{ name: `**ID сервера**:`, value: `${interaction.guild.id}`, inline: true },
])

specchannel.send({ embeds: [Embed] });
}
} catch (error) {
console.error(`An error occurred: ${error}`);
}
@</Almaz> try it
</> Almaz </>
</> Almaz </>9mo ago
thx @Булочка | pasha_boez Is it possible to separate the content? ex.: Content: member: @</Almaz> time: 60m reason: offtop
Булочка | pasha_boez
Use .join("\n") instead of .join(" ")
</> Almaz </>
</> Almaz </>9mo ago
thx!
Булочка | pasha_boez
Where u create content const
</> Almaz </>
</> Almaz </>9mo ago
Is this how it should be?
No description
Булочка | pasha_boez
Remove spaces 🙂 Hard to edit code from mobile
</> Almaz </>
</> Almaz </>9mo ago
oh, understand
Булочка | pasha_boez
And twend .
</> Almaz </>
</> Almaz </>9mo ago
what is "twend" maybe "second"?
Булочка | pasha_boez
2 Yeah, sorry Want to 😴
</> Almaz </>
</> Almaz </>9mo ago
I still need to do an essay in English tomorrow I also didn't go to school for a week ye
Булочка | pasha_boez
Good luck to you with it! Code work?
</> Almaz </>
</> Almaz </>9mo ago
hah, thanks sec
</> Almaz </>
</> Almaz </>9mo ago
working
No description
</> Almaz </>
</> Almaz </>9mo ago
@Булочка | pasha_boez if you haven't seen yet oh timing
</> Almaz </>
</> Almaz </>9mo ago
thank you so much for help, goodnight! and, can you add to friends me? thank you!
Булочка | pasha_boez
+. Thanks You're welcome 🙂
</> Almaz </>
</> Almaz </>9mo ago
goodnight!