You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Dharkael edited this page Feb 12, 2017
·
1 revision
If you are importing the master branch you can use the Clear() method of the UpdatesChannel:
funcmain() {
bot, err:=tgbotapi.NewBotAPI("MyAwesomeBotToken")
iferr!=nil {
log.Panic(err)
}
bot.Debug=truelog.Printf("Authorized on account %s", bot.Self.UserName)
u:=tgbotapi.NewUpdate(0)
u.Timeout=60updates, err:=bot.GetUpdatesChan(u)
// Optional: wait for updates and clear them if you don't want to handle// a large backlog of old messagestime.Sleep(time.Millisecond*500)
updates.Clear()
forupdate:=rangeupdates {
ifupdate.Message==nil {
continue
}
// Add logic here
}
}
Up to version 4.6 you have to do it manually:
funcmain() {
bot, err:=tgbotapi.NewBotAPI("MyAwesomeBotToken")
iferr!=nil {
log.Panic(err)
}
bot.Debug=truelog.Printf("Authorized on account %s", bot.Self.UserName)
u:=tgbotapi.NewUpdate(0)
u.Timeout=60updates, err:=bot.GetUpdatesChan(u)
// Optional: wait for updates and clear them if you don't want to handle// a large backlog of old messagestime.Sleep(time.Millisecond*500)
forlen(updates) !=0 {
<-updates
}
forupdate:=rangeupdates {
ifupdate.Message==nil {
continue
}
// Add logic here
}
}