gpt4 book ai didi

Telethon 无法再获取聊天实体

转载 作者:行者123 更新时间:2023-12-03 08:31:31 28 4
gpt4 key购买 nike

我重新激活了“旧”机器人并收到此错误:

telethon\utils.py", line 138, in _raise_cast_fail        
raise TypeError('Cannot cast {} to any kind of {}.'.format(
TypeError: Cannot cast coroutine to any kind of Peer.

经过一番尝试...我发现在功能中进行白名单聊天时会出现此错误:

@bot.on(events.NewMessage(chats=bot.get_entity(config_group),pattern='/hello'))
async def hello(event):

我的解决方法是:

@bot.on(events.NewMessage(pattern='/hello'))
async def hello(event):

if int(event.chat_id) == int(config_group):

它有效,但能持续多久?我想知道我是否做错了什么? (我的意思是在白名单参数中,该函数不会等待 - 如果这就是原因)但它在一周前起作用,所以......

谢谢您的帮助:)

最佳答案

ID和用户名可以传递给chats=参数,Telethon将自动获取实体。

@bot.on(events.NewMessage(chats=chat_id, pattern='/hello'))
async def hello(event):
# do your things

就您遇到的错误而言,get_entity返回协程,因此必须等待它。

>> TypeError: Cannot cast coroutine to any kind of Peer.

关于Telethon 无法再获取聊天实体,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/64929717/

28 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com