如何检查bot-用户是特定频道的成员还是聊天成员?
我是蟒蛇-电报-机器人的新手。所以,请给我完整的回答。Ps。我用的是python,我用的方法是:成员()。
def is_member(update, context):
userid = update.effective_user.id
chatid = "@chatusername"
try:
res = context.bot.get_chat_member(chat_id=chatid, user_id=userid)
if res.status in ['member', 'administrator']:
return True
except Exception as e:
return False此功能只适用于某些聊天和电报频道,但有时我会遇到错误(telegram.error.BadRequest: User )。但我确信用户是电报频道的一员,如果您有更好的解决方案,请与我们分享。
发布于 2022-05-19 18:10:10
如果您想在一个组或其他地方找到一个成员,首先您需要知道目标组的id。然后你要看到目标用户的ID。
当用户向bot发送消息时,让我们检索此信息。
def check_user_in_the_group(update,context):
group_chat_id = update.message.chat.id #replace this with group id number, if you already know it
user_id = update.message.from_user.id #replace this with user id number, if you already know it
check = context.bot.getChatMember(chat_id,user_id) #check if the user exist in the target group
if check: #If check variable isn't null, user is in the group
print('user is in the chat')
else:
print('Not found')https://stackoverflow.com/questions/71754736
复制相似问题