i want to put the executor name in the embed ban message but i have an error

j
9 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!
PAIDODAMASTIS
PAIDODAMASTISOP10mo ago
here is my code
const { SlashCommandBuilder, PermissionFlagsBits } = require('discord.js');

module.exports = {
data: new SlashCommandBuilder()
.setName('ban')
.setDescription('Select a member and ban them.')
.addUserOption(option =>
option
.setName('target')
.setDescription('The member to ban')
.setRequired(true))
.addStringOption(option =>
option
.setName('reason')
.setDescription('The reason for banning'))
.setDefaultMemberPermissions(PermissionFlagsBits.BanMembers)
.setDMPermission(false),

async execute(interaction) {
try{

const target = interaction.options.getUser('target');
const reason = interaction.options.getString('reason') ?? 'No reason provided';
const executor = interaction.options.getUser('executor');

const title = '**✅ User Banned Successfully**';
const description = `\`\`\` Banned ${target.username} executor: ${executor.username} reason: ${reason}\`\`\``;

await interaction.guild.members.ban(target)
.then(() => {
const embed = {
color: 0x0099ff,
title: title,
description: description,
timestamp: new Date(),
};
interaction.reply({ embeds: [embed] });
})
} catch (error) {
console.error(error);


const title = ('**❌ Command Failed**');
const description = `\`\`\`Unable to Ban the member, check my permissions and try again\`\`\``


const embed = {
color: 0xFF0000,
title: title,
description: description,
timestamp: new Date(),
};

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


}
},
};
const { SlashCommandBuilder, PermissionFlagsBits } = require('discord.js');

module.exports = {
data: new SlashCommandBuilder()
.setName('ban')
.setDescription('Select a member and ban them.')
.addUserOption(option =>
option
.setName('target')
.setDescription('The member to ban')
.setRequired(true))
.addStringOption(option =>
option
.setName('reason')
.setDescription('The reason for banning'))
.setDefaultMemberPermissions(PermissionFlagsBits.BanMembers)
.setDMPermission(false),

async execute(interaction) {
try{

const target = interaction.options.getUser('target');
const reason = interaction.options.getString('reason') ?? 'No reason provided';
const executor = interaction.options.getUser('executor');

const title = '**✅ User Banned Successfully**';
const description = `\`\`\` Banned ${target.username} executor: ${executor.username} reason: ${reason}\`\`\``;

await interaction.guild.members.ban(target)
.then(() => {
const embed = {
color: 0x0099ff,
title: title,
description: description,
timestamp: new Date(),
};
interaction.reply({ embeds: [embed] });
})
} catch (error) {
console.error(error);


const title = ('**❌ Command Failed**');
const description = `\`\`\`Unable to Ban the member, check my permissions and try again\`\`\``


const embed = {
color: 0xFF0000,
title: title,
description: description,
timestamp: new Date(),
};

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


}
},
};
Mark
Mark10mo ago
is there a reason you're having the executor be an option in the slash command and not just interaction.member, the one who used the command :Thonk: you don't even have an executor option in your slash command data you should really double check your code for things that do or don't exist
PAIDODAMASTIS
PAIDODAMASTISOP10mo ago
i want to get the executor username so i can tag him in the mbed msg
Mark
Mark10mo ago
ok and? that addresses nothing of what i said
PAIDODAMASTIS
PAIDODAMASTISOP10mo ago
hold on ohhhh i get it
Mark
Mark10mo ago
a) you have no option named executor b) why would you even have an option for that c) why not just use interaction.member or interaction.user, the member (user) object that invoked the command to ban?
PAIDODAMASTIS
PAIDODAMASTISOP10mo ago
yeah i get it i am stupid i just want to tag him i dont want him to be an option i get it
Mark
Mark10mo ago
you got it, just needs a little tweaking! 👍
Want results from more Discord servers?
Add your server