#Pretty basic (I know), but how would I add a user input to a slash command using this type of syntax

1 messages ยท Page 1 of 1 (latest)

crimson hollow
#

Looks like you want to add something aside from user paramater, right?

long pollen
#

yeah

#

like e.g text to echo

#

and then it sends that text back in a message

#

I want to basically access it in the async execute function

crimson hollow
#

You have to duplicate your .addStringOption and modify the name. Then, you don't need to pass it, you will get the parameter like you wrote at line 15

long pollen
#

oh shit really?

#

hmm

#

alright one second lemme try it out :)

#

Can I access it like this then @crimson hollow ?

crimson hollow
long pollen
#

alright one seocnd

#

like that?

#

or somewhere else

crimson hollow
#

Everything inside .addStringOption was good in the previous screenshot

#

The modification happens at line 15

long pollen
#

sorry this is literally my first time EVER using discord.js - I am coming from a solely discord.py background ๐Ÿ˜‚

long pollen
crimson hollow
#

If you copy-paste the code next time, rather than screenshoot, I could modify it for you

long pollen
#

lmao alr sorry

#

ok am still confused

#
const { SlashCommandBuilder } = require('@discordjs/builders');

module.exports = {
    data: new SlashCommandBuilder()
        .setName('ping')
        .setDescription('Replies with Pong!')
        // Add an option to accept user input
        .addStringOption(option =>
            option.setName('input')
                .setDescription("The input to echo back")
                .setRequired(true)
        )
        .getString("input"),
    async execute(interaction) {
        
        /* const ping = interaction.options.getString('ping');
        return interaction.reply(ping); */
    },
};
#

where the hell would I put the thing to get the thing?! joyous

crimson hollow
#
const { SlashCommandBuilder } = require('@discordjs/builders');

module.exports = {
    data: new SlashCommandBuilder()
        .setName('ping')
        .setDescription('Replies with Pong!')
        // Add an option to accept user input
        .addStringOption(option =>
            option.setName('input')
                .setDescription("The input to echo back")
                .setRequired(true)
        )
    async execute(interaction) {
        console.log(interaction.options.getString('input'));
        /* const ping = interaction.options.getString('ping');
        return interaction.reply(ping); */
    },
};
long pollen
#

๐Ÿ‘€

#

hm

#

ok

#

OHHH

#

that makes sense joyous

#

alr one sec

crimson hollow
#

If you were writing it like:

const { SlashCommandBuilder } = require('@discordjs/builders');

let parameter_name = "input";
module.exports = {
    data: new SlashCommandBuilder()
        .setName('ping')
        .setDescription('Replies with Pong!')
        // Add an option to accept user input
        .addStringOption(option =>
            option.setName(parameter_name)
                .setDescription("The input to echo back")
                .setRequired(true)
        )
    async execute(interaction) {
        console.log(interaction.options.getString(parameter_name));
        /* const ping = interaction.options.getString('ping');
        return interaction.reply(ping); */
    },
};
#

It would make even more sense

long pollen
#

ohhh alr

#

thanks btw - it worked good :D

#

oh uh

#

@crimson hollow

#

modified it a bit

#

and it is scuffed now

#

why is that?

crimson hollow
#

This file looks good. Also it looks like the error originates in some other place

long pollen
#

hm alr

#

oh fixed it