Skip to content

Commit 80d2512

Browse files
committed
fix case sensitivity of unprefixed messageCreate commands
1 parent e475310 commit 80d2512

3 files changed

Lines changed: 14 additions & 14 deletions

File tree

dist/handlers/events/messageCreate.js

Lines changed: 6 additions & 6 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

dist/handlers/events/messageCreate.js.map

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/handlers/events/messageCreate.ts

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -12,12 +12,10 @@ export default new DiscordEventHandler({
1212
description: "This event is fired when someone sends a message",
1313
listener: async function (message) {
1414
const prefix = await this.getPrefix(message)
15-
16-
const args = message.content
17-
.slice(prefix?.length ?? 0)
18-
.trim()
19-
.split(/ +/g)
20-
const name = prefix ? args.shift()?.toLowerCase() : args[0]
15+
const content = message.content.trim()
16+
const hasPrefix = prefix !== null
17+
const rawArgs = (hasPrefix ? content.slice(prefix!.length) : content).trim().split(/ +/g)
18+
const name = rawArgs[0]?.toLowerCase()
2119

2220
const commands = this.commands.get("messageCreate").filter(
2321
// Allow always execute commands
@@ -26,10 +24,12 @@ export default new DiscordEventHandler({
2624
(// Check if it matches the command name or one of aliases
2725
(cmd.name === name || !!cmd.data.aliases?.includes(name!)) &&
2826
// If unprefixed there can be no prefix
29-
(cmd.data.unprefixed ? true : !!prefix))
27+
(cmd.data.unprefixed ? true : hasPrefix))
3028
)
3129

3230
for (const command of commands) {
31+
const args = command.name ? rawArgs.slice(1) : rawArgs
32+
3333
Interpreter.run({
3434
obj: message,
3535
command,

0 commit comments

Comments
 (0)