diff --git a/src/command-handler.ts b/src/command-handler.ts index f74a4428..fc1930b3 100644 --- a/src/command-handler.ts +++ b/src/command-handler.ts @@ -126,7 +126,8 @@ export class CommandHandler { // returns false if the message was not a wheatley command private async handle_text_command(message: Discord.Message, prev_command_obj?: TextBasedCommand) { - const match = message.content.match(CommandHandler.command_regex); + const cmd = message.content.replace(new RegExp(String.raw`^\s*<@${this.wheatley.client.user?.id}>\s*`), ""); + const match = cmd.match(CommandHandler.command_regex); if (!match) { // starts with ! but doesn't match the command regex return false; @@ -143,7 +144,7 @@ export class CommandHandler { return false; } - let command_body = message.content.substring(match[0].length).trim(); + let command_body = cmd.substring(match[0].length).trim(); let command = this.text_commands[command_name]; const command_obj = prev_command_obj ? new TextBasedCommand(prev_command_obj, command_name, command, message) @@ -292,7 +293,8 @@ export class CommandHandler { if (message.guildId !== this.wheatley.guild.id) { return; } - if (message.content.startsWith("!")) { + const cmd = message.content.replace(new RegExp(String.raw`^\s*<@${this.wheatley.client.user?.id}>\s*`), ""); + if (cmd.startsWith("!")) { await this.handle_text_command(message); } } catch (e) {