Skip to content

Commit 5e99c8b

Browse files
committed
messageCreate case-sensitive name fix if unprefixed
1 parent d5a6952 commit 5e99c8b

4 files changed

Lines changed: 29 additions & 29 deletions

File tree

dist/handlers/events/messageCreate.d.ts.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.

dist/handlers/events/messageCreate.js

Lines changed: 13 additions & 13 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: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -8,28 +8,28 @@ import { DiscordEventHandler } from "../../structures/extended/DiscordEventHandl
88

99
export default new DiscordEventHandler({
1010
name: "messageCreate",
11-
version: "1.0.1",
11+
version: "1.0.2",
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 && content.toLowerCase().startsWith(prefix.toLowerCase())
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(
23-
// Allow always execute commands
2421
(cmd) =>
22+
// Allow always execute commands
2523
!cmd.name ||
26-
(// Check if it matches the command name or one of aliases
27-
(cmd.name === name || !!cmd.data.aliases?.includes(name!)) &&
28-
// If unprefixed there can be no prefix
29-
(cmd.data.unprefixed ? true : !!prefix))
24+
// Check if it matches the command name or one of aliases
25+
((cmd.name === name ||
26+
!!cmd.data.aliases?.includes(name!)) &&
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,
@@ -44,5 +44,5 @@ export default new DiscordEventHandler({
4444
})
4545
}
4646
},
47-
intents: ["GuildMessages", "DirectMessages"],
48-
})
47+
intents: ["GuildMessages", "DirectMessages", "MessageContent"],
48+
})

0 commit comments

Comments
 (0)