Member Server Kick reason is not defined

Hey, I have a /server kick command but the reason somehow doesn't come through in Discord. Here's my code: In the logs, it says "Kein Grund angegeben" and in the audit logs, there's no reason given for the kick. But in the Command Respond Embed the Reason is given...
if (interaction.options.getSubcommand() === "kick") {

if (!HasBanAndKickPermissions) {
return interaction.reply({ content: `Keine Berechtigung!`, ephemeral: true });
};



const target = interaction.options.getUser('benutzer');
const reason = interaction.options.getString('grund');


const guild = interaction.guild;
const guildName = guild.name;
const guildIcon = guild.iconURL({ dynamic: true, size: 4096 });



const kickEmbed = new EmbedBuilder()
.setTitle(`${target.tag} wurde gekickt!`)
.setColor('#993200')
.addFields(
{
name: 'Grund:',
value: stripIndents`\`${reason ?? 'Kein Grund angegeben'}\``,
inline: true,
},
);


const kickEmbeddm = new EmbedBuilder()
.setAuthor({ name: guildName, iconURL: guildIcon })
.setTitle(`Du wurdest gekickt!`)
.setColor('#993200')
.addFields(
{
name: 'Grund:',
value: stripIndents`\`${reason ?? 'Kein Grund angegeben'}\``,
inline: true,
},
);

let failsafe = false;
target.send({ embeds: [kickEmbeddm] }).catch(e => {});
await interaction.guild.members.kick(target, { reason: `${reason ?? 'Kein Grund angegeben'} ~${interaction.member.user.tag}` }).catch(e => {
(failsafe = true)
target.send({ embeds: 'Bei deinem Kick ist ein Fehler aufgetreten.' }).catch(e => {});
return interaction.reply({ content: `Es ist ein Fehler aufgetreten. \`${e.message}\``});
});

if (failsafe) return;


return interaction.reply({ embeds: [kickEmbed]});



};
if (interaction.options.getSubcommand() === "kick") {

if (!HasBanAndKickPermissions) {
return interaction.reply({ content: `Keine Berechtigung!`, ephemeral: true });
};



const target = interaction.options.getUser('benutzer');
const reason = interaction.options.getString('grund');


const guild = interaction.guild;
const guildName = guild.name;
const guildIcon = guild.iconURL({ dynamic: true, size: 4096 });



const kickEmbed = new EmbedBuilder()
.setTitle(`${target.tag} wurde gekickt!`)
.setColor('#993200')
.addFields(
{
name: 'Grund:',
value: stripIndents`\`${reason ?? 'Kein Grund angegeben'}\``,
inline: true,
},
);


const kickEmbeddm = new EmbedBuilder()
.setAuthor({ name: guildName, iconURL: guildIcon })
.setTitle(`Du wurdest gekickt!`)
.setColor('#993200')
.addFields(
{
name: 'Grund:',
value: stripIndents`\`${reason ?? 'Kein Grund angegeben'}\``,
inline: true,
},
);

let failsafe = false;
target.send({ embeds: [kickEmbeddm] }).catch(e => {});
await interaction.guild.members.kick(target, { reason: `${reason ?? 'Kein Grund angegeben'} ~${interaction.member.user.tag}` }).catch(e => {
(failsafe = true)
target.send({ embeds: 'Bei deinem Kick ist ein Fehler aufgetreten.' }).catch(e => {});
return interaction.reply({ content: `Es ist ein Fehler aufgetreten. \`${e.message}\``});
});

if (failsafe) return;


return interaction.reply({ embeds: [kickEmbed]});



};
No description
No description
No description
3 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!
d.js docs
d.js docs10mo ago
Documentation suggestion for @Marc Anthony: :method: GuildMemberManager#kick() Kicks a user from the guild. (more...)
Amgelo
Amgelo10mo ago
kick takes two arguments, the target and the reason (string) you're providing the target but the reason as an object
Want results from more Discord servers?
Add your server