From 50843edf6a2236144aa4e9bdb29e04240126a251 Mon Sep 17 00:00:00 2001 From: YuFengZe <65108397+YuFengZe@users.noreply.github.com> Date: Sun, 31 Oct 2021 22:01:14 +0800 Subject: [PATCH] Bug Fixed MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 解决发送“我是谁”却返回机器人信息的奇怪问题。 --- src/Module/Example/Hello.php | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/src/Module/Example/Hello.php b/src/Module/Example/Hello.php index d0566273..b3761855 100644 --- a/src/Module/Example/Hello.php +++ b/src/Module/Example/Hello.php @@ -10,6 +10,7 @@ use ZM\Annotation\Swoole\OnOpenEvent; use ZM\Annotation\Swoole\OnRequestEvent; use ZM\API\CQ; use ZM\API\TuringAPI; +use ZM\API\OneBotV11; use ZM\ConnectionManager\ConnectionObject; use ZM\Console\Console; use ZM\Annotation\CQ\CQCommand; @@ -49,8 +50,12 @@ class Hello * @CQCommand("我是谁") */ public function whoami() { - $user = ctx()->getRobot()->getLoginInfo(); - return "你是" . $user["data"]["nickname"] . ",QQ号是" . $user["data"]["user_id"]; + $bot = ctx() -> getRobot() -> getLoginInfo(); + $botId = $bot["data"]["user_id"]; + $r = OneBotV11::get($botId); + $QQid = ctx() -> getUserId(); + $nick = $r -> getStrangerInfo($QQid)["data"]["nickname"]; + return "你是" . $nick . ",QQ号是" . $QQid; } /**