python-wechaty
python-wechaty copied to clipboard
bug:python-wechaty库不能获取到微信备注(alias)
alias = await self.puppet.contact_alias(self.contact_id, new_alias) 此处语句进行备注设置时可以正常运行,但用于Get aias时,产生内部错误,internal error
python版本如果存在alias,则直接替换name字段了。
python版本如果存在alias,则直接替换name字段了。
python版本如果存在alias,则直接替换name字段了。
嗷嗷,这样啊,谢谢你。这样的话,是只能set 备注了么
alias只能赋值不能获取,赋值 await contact.alias('newalias') 即可,contact的格式是Contact <@b543b89ada0184104fc219f22387b4b52702434250f66fa**>
这样啊,明白了,谢谢你
看了下代码,获取alias可以用contact.payload.alias获取。 contacts: List[Contact] = await bot.Contact.find_all() for contact in contacts: contacts_dict[contact.contact_id] = (contact.name,contact.payload.alias,contact.type())
嗷嗷,学到了,一会去试试。再次感谢大佬!
python版本如果存在alias,则直接替换name字段了。
Thanks for share your understanding about python-wechaty
. But I want to correct you that if there is contact alias, it will return it from contact.alias()
method. alias
is different with name
, and python-wechaty
will not replace name with alias. It will only happen in mention_text
method which whill return alias or name
. @canwushuang hope that it will improve your understanding about python-wechaty
. For details, you can read code from alias method defination.
@Huameng11 you can refer to ding-dong-bot-oop.py to checkout the example code in your learning.
python版本如果存在alias,则直接替换name字段了。
Thanks for share your understanding about
python-wechaty
. But I want to correct you that if there is contact alias, it will return it fromcontact.alias()
method.alias
is different withname
, andpython-wechaty
will not replace name with alias. It will only happen inmention_text
method which whill returnalias or name
. @canwushuang hope that it will improve your understanding aboutpython-wechaty
. For details, you can read code from alias method defination.@Huameng11 you can refer to ding-dong-bot-oop.py to checkout the example code in your learning.
Thanks for sharing! I traced the log and read the contact.py at the beginning, the private function ’str‘ in line 182, it return contact’s alias preferred.
alias只能赋值不能获取,赋值 await contact.alias('newalias') 即可,contact的格式是Contact <@b543b89ada0184104fc219f22387b4b52702434250f66fa**> 。另外,wechaty守护程序需要重启,联系人才能使用新alias搜索,否则只能使用之前的alias。
有没有不用重启wechaty的方法呀?每次重启wechaty后都得重新登陆,contactid也都会改变
怎么样能获取到 微信的昵称呀
there is a name
property in contact class, so you can get the name or alias with the following code:
await contact.ready()
# get the name
contact.name
# get the alias
await contact.alias()
you can read more on wechaty docs website.
联系人类中有一个
name
属性,因此您可以使用以下代码获取名称或别名:await contact.ready() # get the name contact.name # get the alias await contact.alias()
您可以在 wechaty文档网站上阅读更多内容。
class MyBot(Wechaty):
async def on_message(self, contact: Contact) -> None:
await contact.ready()
print(contact.name)
asyncio.run(MyBot().start())
我尝试模仿文档里的方法,来获取 别名或昵称,但是失败了,本人刚学习py,如果作者能够提供完整的代码最好了,谢谢开发者!
2022-11-11 23:48:35,652 - Wechaty - ERROR - internal error <'Message' object has no attribute 'name'>
The parameters of on_message is message instance, not contact. All error infos can be found in terminal. Hope that you can fix this small error.