guide
guide copied to clipboard
Code exerpt is unclear in the options section
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.
Disagree. The example is fine as is
Disagree. The example is fine as is
Can you explain why you feel this way? @adrifcastr
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.