我正在尝试将新用户链接到他的邀请者。 但我在“chat_join_request”事件中找不到有关邀请者的任何信息。 有没有解决方案可以找出用户使用哪个邀请链接加入群组。
bot.on('chat_join_request', async (msg) => {
console.log("new member", msg)
}
消息中没有 inform_link 属性
你不能这样做。
如果你想将用户映射到他们的邀请者,你应该使用
createChatInviteLink
方法为每个邀请者生成新的邀请链接,如果你想的话,你可以稍后使用 name
参数来区分用户(这是简单的方法)或者您可以使用数据库将链接映射到邀请者。
如果您使用
name
参数,您可以轻松地从Update.chat_join_request.invite_link.name
获取邀请链接的名称。
我将简要解释一下流程:
createChatInviteLink
且 name
设置为“u1234”Update.chat_join_request
事件,以下代码可以完成剩下的工作:bot.on('chat_join_request', async (up) => {
console.log("New Request", up)
const name = up.chat_join_request.invite_link.name;
// Removes the "u" from name ("u1234") and we added earlier and gets the `user_id` of the inviter as integer.
const inviterId = parseInt(name.slice(1));
// you can call getChat or getChatMember to get more info on the inviter here
// ...
})
希望这有帮助。