Skip to content
12 changes: 8 additions & 4 deletions botpy/ext/command_util.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
6 changes: 6 additions & 0 deletions botpy/message.py
Original file line number Diff line number Diff line change
Expand Up @@ -235,6 +235,12 @@ def __repr__(self):
return str(self.__dict__)


@property
def api(self):
return self._api



class GroupMessage(BaseMessage):
__slots__ = (
"author",
Expand Down