25 * @param {Client} client
26 */
27
28 async execute(client, interaction) {29 try {
30 const selection = interaction.values[0];
31 const commands = readdirSync(`${process.cwd()}/Commands/Slash/${selection}`).filter(file => file.endsWith(".js")).join(" ").split(".js");
22 * @param {Client} client
23 */
24
25 async execute(client, interaction) {26 try {
27 const title = interaction.fields.getTextInputValue("modal-title");
28 const description = interaction.fields.getTextInputValue("modal-description");
23 * @param {Client} client
24 */
25
26 async execute(client, interaction) {27 try {
28 const testModal = new ModalBuilder()
29 .setCustomId("modal-test")
Any code paths that do not have explicit returns will return undefined
.
It is recommended to replace any implicit dead-ends that return undefined
with a return null
statement.
As a convention, undefined
signals that an unexpected value has been produced as the
result of a logical error in the program.
A null
return, on the other hand, signals that the input to a function was incorrect,
or a value was 'not found'.
Having this distinction in code helps you figure out if something was caused because of a logical error, or malformed input to a function call.
function getUser(name) {
if (userExists(name)) {
return userDb.get(name);
}
// whoops! Implicit undefined return
}
function readFile(fileName) {
if (fs.existsSync(fileName)) {
return fs.readFileSync(fileName, 'utf-8');
}
return; // Implicit undefined return.
}
function getUser(name) {
if (userExists(name)) {
return userDb.get(name);
}
// `null` indicates there is no such user.
return null;
}
function readFile(fileName) {
if (fs.existsSync(fileName)) {
return fs.readFileSync(fileName, 'utf-8');
}
// `null` indicates there is no such file.
return null;
}