410 if (usedStocksRecently.has(message.author.id)) {
411 message.reply(embed.error(`You need to wait ${timeout / 1000} seconds before asking for stocks again.`, "ERR_RATE_LIMIT", "Slow down!"));
412 } else {
413 (async () => {414 if (!stocksEnabled) {
415 message.reply(embed.error("Stock lookup isn't currently working. Sorry about that.", "ERR_NO_STOCK_KEY"));
416 return null;
362 let city = !(["metric", "imperial"].includes(norm(args[0]))) ? args.slice(0).join(" ") : args.slice(1).join(" ");
363 if (!city) {
364 message.reply(embed.error("You didn't include a city name. Re-run the command with the city name.", `args: ${args.toString()}`));
365 return null;366 }
367 let windUnits = units == "imperial" ? "mph" : "m/s";
368
225 case "amiadmin":
226 if (!message.member) return message.reply("Trick question.");
227 if (!message.member.hasPermission("ADMINISTRATOR")) return message.reply("you're not admin!");
228 else return message.reply("you are admin!");229 case "testdm":
230 message.author.send("Looks like the DM worked! You can send commands in here.")
231 .catch(error => {
466 message.reply(embed.error("You didn't include any arguments. Re-run the command with the summoner name."));
467 return;
468 }
469 (async () => {470 let reg = "NA";
471
472 if (args[1]) {
549 const mbed = new Discord.MessageEmbed()
550 .setColor(6765239)
551 .setTitle("Spell Check");
552 items.some(({ fragment, suggestions }) => {553 let addition = `~~${fragment}~~ → **${suggestions.join("**, **") || "No suggestions"} **\n`;
554 if (desc.length + addition.length > 2000) {
555 mbed.setFooter("This spellcheck has been shortened.");
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;
}