tucnak / telebot

Telebot is a Telegram bot framework in Go.
MIT License
4.04k stars 469 forks source link

How to check that user blocked and stop bot? #649

Closed region23 closed 9 months ago

region23 commented 9 months ago

How to check that user blocked and stop bot? Can't found this in docs or code.

akumarujon commented 9 months ago

You can try sending a message and check if the err is equal to ErrBlockedByUser.

msg, err := b.Send(&tele.User{ID: id}, "Hello")

if err != nil {
fmt.Println(err)
}

fmt.Println(err == tele.ErrBlockedByUser)

I blocked the bot and tried to send a Message, and in this case, it printed true in console:

image