diff --git a/botpy/ext/command_util.py b/botpy/ext/command_util.py index 8f26b2b..979b5d9 100644 --- a/botpy/ext/command_util.py +++ b/botpy/ext/command_util.py @@ -20,10 +20,14 @@ async def decorated(*args, **kwargs): message: BaseMessage = kwargs["message"] for command in self.commands: if command in message.content: - # 分割指令后面的指令参数 - params = message.content.split(command)[1].strip() - kwargs["params"] = params - return await func(*args, **kwargs) + # 剔除消息文本中@机器人的字符串 + content = message.content.replace(f"<@!{(await message.api.me())['id']}>", "") + content_split = content.lstrip().split(command) + # 当指令出现在消息文本(已剔除@机器人的信息)的开头执行指令 + if len(content_split[0]) == 0: + # 分割指令后面的指令参数 + kwargs["params"] = content_split[1].strip() + return await func(*args, **kwargs) return False return decorated diff --git a/botpy/message.py b/botpy/message.py index 20918b4..78c1a10 100644 --- a/botpy/message.py +++ b/botpy/message.py @@ -235,6 +235,12 @@ def __repr__(self): return str(self.__dict__) + @property + def api(self): + return self._api + + + class GroupMessage(BaseMessage): __slots__ = ( "author",