Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 6 additions & 6 deletions dist/handlers/events/messageCreate.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion dist/handlers/events/messageCreate.js.map

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

14 changes: 7 additions & 7 deletions src/handlers/events/messageCreate.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,10 @@ export default new DiscordEventHandler({
description: "This event is fired when someone sends a message",
listener: async function (message) {
const prefix = await this.getPrefix(message)

const args = message.content
.slice(prefix?.length ?? 0)
.trim()
.split(/ +/g)
const name = prefix ? args.shift()?.toLowerCase() : args[0]
const content = message.content.trim()
const hasPrefix = prefix !== null
const rawArgs = (hasPrefix ? content.slice(prefix!.length) : content).trim().split(/ +/g)
const name = rawArgs[0]?.toLowerCase()

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

for (const command of commands) {
const args = command.name ? rawArgs.slice(1) : rawArgs

Interpreter.run({
obj: message,
command,
Expand Down
Loading