guide icon indicating copy to clipboard operation
guide copied to clipboard

Code exerpt is unclear in the options section

Open joeldesante opened this issue 4 years ago • 3 comments

The style used in the following excerpt is confusing.

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

const data = new SlashCommandBuilder()
	.setName('echo')
	.setDescription('Replies with your input!')
	.addStringOption(option =>
		option.setName('input')
			.setDescription('The input to echo back')
			.setRequired(true));

When I was following this guide, it was not immediately obvious to me that I needed to return the value option due to how the above code is written. For those who exclusively work in JavaScript, this may be a trivial issue, however, for others, it may not be obvious that shorthand is being used.

I lost about 15-20 mins before I realized this.

See https://discordjs.guide/interactions/registering-slash-commands.html#options

I suggest changing it to:

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

const data = new SlashCommandBuilder()
	.setName('echo')
	.setDescription('Replies with your input!')
	.addStringOption(option => {
		return option.setName('input')
			.setDescription('The input to echo back')
			.setRequired(true));
        }

I feel this will make it more clear.

joeldesante avatar Sep 22 '21 21:09 joeldesante

Disagree. The example is fine as is

castdrian avatar Sep 22 '21 21:09 castdrian

Disagree. The example is fine as is

Can you explain why you feel this way? @adrifcastr

joeldesante avatar Sep 23 '21 05:09 joeldesante

This is fine to me. Using array functions without curly braces (which enables implicit returns) is a language feature, there are multiple ways to use them. Although personally I'd do:

new SlashCommandBuilder()
	.addStringOption(option =>
		option.setName('input')
			.setDescription('The input to echo back')
			.setRequired(true)
	);

Just to line up the opening and closing parens.

Danktuary avatar Sep 26 '21 19:09 Danktuary