Skip to main content
Improve formatting
Source Link
janos
  • 113.1k
  • 15
  • 154
  • 396

You can simplify all of the basic text responses by putting them into a table. Instead of:
if (message.content === "foo") message.channel.sendMessage("bar");
Do

if (message.content === "foo") message.channel.sendMessage("bar");

Do:
var responses = {"foo": "bar"} if (responses[message]) message.channel.sendMessage(responses[message]); It

var responses = {"foo": "bar"};
if (responses[message]) message.channel.sendMessage(responses[message]);

It may be more complicated for shorter stacks of if else statements but it is more efficient for large ones like the one in your code.

You can simplify all of the basic text responses by putting them into a table Instead of:
if (message.content === "foo") message.channel.sendMessage("bar");
Do:
var responses = {"foo": "bar"} if (responses[message]) message.channel.sendMessage(responses[message]); It may be more complicated for shorter stacks of if else statements but it is more efficient for large ones like the one in your code.

You can simplify all of the basic text responses by putting them into a table. Instead of:

if (message.content === "foo") message.channel.sendMessage("bar");

Do:

var responses = {"foo": "bar"};
if (responses[message]) message.channel.sendMessage(responses[message]);

It may be more complicated for shorter stacks of if else statements but it is more efficient for large ones like the one in your code.

Source Link

You can simplify all of the basic text responses by putting them into a table Instead of:
if (message.content === "foo") message.channel.sendMessage("bar");
Do:
var responses = {"foo": "bar"} if (responses[message]) message.channel.sendMessage(responses[message]); It may be more complicated for shorter stacks of if else statements but it is more efficient for large ones like the one in your code.