【发布时间】:2021-10-22 04:57:52
【问题描述】:
我正在尝试让我的电报机器人在电报上提及没有用户名并希望使用用户 ID 提及他们的用户。 下面是我的python代码..它不会标记那些没有用户名的人。
def welcome(update, context, new_member):
# Greets a person who joins the chat
message = update.message
chat_id = message.chat.id
if new_member.username is None:
username = "["+new_member.first_name+"](tg://user?id="+str(new_member.id)+")"
else:
username = new_member.username
logger.info(
"%s joined to chat %d (%s)",
escape(username),
chat_id,
escape(message.chat.title),
)
text = (
f"Hello @{username}! Welcome to the {message.chat.title} "
"telegram group!\n"
"Please introduce yourself."
)
context.bot.send_message(chat_id=chat_id, text=text)
根据link:可以通过带有标记的数字ID来提及用户: 降价风格
要使用此模式,请在使用 sendMessage 时在 parse_mode 字段中传递 Markdown。在您的消息中使用以下语法:
内联提及用户
我无法在我的代码中应用它并让它工作。有人可以帮我吗? 此处已成功应用该功能
https://github.com/domdorn/telegram/commit/ea308cadb739a9a018c7fbabc16824e2ff82d415
我想在我的代码中应用相同的内容,以便它会提及没有用户名和 ID 的用户。
【问题讨论】:
标签: python telegram python-telegram-bot