大家早上好,我尝试编写一个用于电报的机器人。我需要从用户名中获取用户 [对象]。可以办到?我试图用谷歌搜索它,但我没有找到任何东西,而且我读到没有办法做到这一点。
代码:
https://i.imgur.com/ptDNTGp.png
bot.onText(/\/avvia/, (msg, match) => { // the user must write /avvia @username
const chatId = msg.chat.id;
if(chatId != ChatGroup) { return; } // Check if the command is executed in the right group [ChatGroup is a const with value chat.id]
if(match.input == '/avvia') // Check if it's just typing the command
{
bot.sendMessage(chatId, 'Only /avvia');
return;
}
var aCaso = match.input.replace('/avvia ', '').split(' ');
const resp = aCaso[0];
bot.getChatMember(chatId, resp /* <= THIS ONE*/).then( response => { // Check if the forwarded user is in the group
//console.log(response) // But RESP is wrong because is
if(response.status == 'left' || response.status == 'kicked') // getChatMember(string|int chatId, int userId), and not a username
{
bot.sendMessage(chatId, 'Not in the group');
return
}
})
//console.log(resp);
});