Skip to content

Commit 95c6253

Browse files
authored
Update your-first-bot.md (AnIdiotsGuide#175)
`startsWith(\`${prefix}ping\`)` to `startsWith(`\`${prefix}ping\`)`
1 parent 3759e19 commit 95c6253

File tree

1 file changed

+1
-1
lines changed

1 file changed

+1
-1
lines changed

first-bot/your-first-bot.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,7 @@ The changes to the code are still simple. Let's go through them:
9797

9898
* `const prefix = "!";` defines the prefix as the exclamation mark. You can change it to something else, of course.
9999
* The line `if (!msg.content.startsWith(prefix)) return;` is a small bit of optimization which reads: "If the message does not start with my prefix, stop what you're doing". This prevents the rest of the function from running, making your bot faster and more responsive.
100-
* The commands have changed so use this prefix, where `startsWith(\`${prefix}ping\`)` would only be triggered when the message starts with `!ping`.
100+
* The commands have changed so use this prefix, where `startsWith(`\`${prefix}ping\`)` would only be triggered when the message starts with `!ping`.
101101

102102
The second point is just as important as having a single `message` event handler. Let's say the bot receives a hundred messages every minute \(not much of an exaggeration on popular bots\). If the function does not break off at the beginning, you are processing these hundred messages in each of your command conditions. If, on the other hand, you break off when the prefix is not present, you are saving all these processor cycles for better things. If commands are 1% of your messages, you are saving 99% processing power...
103103

0 commit comments

Comments
 (0)