Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

294
Views
How do you pass a string as an option in Discord.js

I'm using Discord.js V13 (Node JS v16.8.0) and wanted to pass a string as an option

module.exports = {
    data: new SlashCommandBuilder()
        .setName('punish')
        .setDescription('Punish a Guild Member')
          .addUserOption(option =>
            option.setName('target')
              .setDescription('Select a user')
              .setRequired(true))

          .addStringOption(option =>
            option.setName('category')
              .setDescription('Choose punishment')
              .setRequired(true)
              .addChoice('Kick', 'kick')
              .addChoice('Ban', 'ban')),

async execute(interaction) {
  const member = interaction.options.getMember('target');
  const type = interaction.options.getString('type')
  
  await member.type(`Reason: Spam`) //member.ban() / member.kick()
  await interaction.reply("Kicked member successfully.")

  },
};

I've got the user's selection (category) and would like to execute a punishment in accordance with it.

When I execute member.type() I of course get an error since I can not pass a string as an option, Is there any way I could possibly do this?

I know you can do if (type == 'kick') { //... } if (type == 'ban') { //... } but I think my solution is more convenient and useful

about 4 years ago · Santiago Trujillo
1 answers
Answer question

0

You can access a property of member by its name (and call its methods) like this:

member["propertyName"]();

So in your use case:

member[type]('Reason: Spam');
about 4 years ago · Santiago Trujillo Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!