我正在用golang编程语言编写电报机器人。如何在用户离开或加入时发送消息? 我试试这个
if (message.UserJoined == true){
bot.SendMessage(message.Chat, "" ,nil)
}
但它不起作用,我收到此错误
./main.go:291: invalid operation: message.UserJoined == true (mismatched types telebot.User and bool)
答案 0 :(得分:1)
UserJoined是用户结构定义:
// UserJoined可能是Bot本身。
UserJoined User `json:"new_chat_participant"`
它与bool
不匹配在没有看到其余代码的情况下,我无法告诉您正在测试消息的内容。
我很喜欢你需要的东西
if message.UserJoined.ID > 0 {
//Dosomething
}
答案 1 :(得分:0)
在这种情况下,因为你试图比较两种不同的类型,它是失败的。但是,我不确定您使用的是哪种API,或者您是否使用自己的API,因此我不确定message.UserJoined应该表示什么。但是我认为根据你的明显用例,你应该将它与nil进行比较。即使用message.UserJoined!= nil {}