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