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 toolkit14mo 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
AlmazOP14mo ago
не работает, брат хлеб An error occurred: Error: Received one or more errors @Булочка | pasha_boez прислать код?
Булочка | pasha_boez
#rules 2 😦 Yes, if you can
Almaz
AlmazOP14mo 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
AlmazOP14mo 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
AlmazOP14mo 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
AlmazOP14mo ago
?
No description
Булочка | pasha_boez
Yes @</Almaz>
Almaz
AlmazOP14mo ago
went to the toilet
Булочка | pasha_boez
Oh, sorry
Almaz
AlmazOP14mo 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
AlmazOP14mo ago
oh, no
Almaz
AlmazOP14mo 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
AlmazOP14mo ago
see
Булочка | pasha_boez
Also you can create embed without fields and add them after check for options length
Almaz
AlmazOP14mo 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
AlmazOP14mo 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
AlmazOP14mo ago
thx!
Булочка | pasha_boez
Where u create content const
Almaz
AlmazOP14mo ago
Is this how it should be?
No description
Булочка | pasha_boez
Remove spaces 🙂 Hard to edit code from mobile
Almaz
AlmazOP14mo ago
oh, understand
Булочка | pasha_boez
And twend .
Almaz
AlmazOP14mo ago
what is "twend" maybe "second"?
Булочка | pasha_boez
2 Yeah, sorry Want to 😴
Almaz
AlmazOP14mo 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
AlmazOP14mo ago
hah, thanks sec
Almaz
AlmazOP14mo ago
working
No description
Almaz
AlmazOP14mo ago
@Булочка | pasha_boez if you haven't seen yet oh timing
Almaz
AlmazOP14mo ago
thank you so much for help, goodnight! and, can you add to friends me? thank you!
Булочка | pasha_boez
+. Thanks You're welcome 🙂
Almaz
AlmazOP14mo ago
goodnight!
Want results from more Discord servers?
Add your server