go-telegram / bot

Telegram Bot API Go framework
MIT License
512 stars 46 forks source link

Panic when editing a message #101

Open CodeExplorerX opened 4 days ago

CodeExplorerX commented 4 days ago

Panic occurs when editing a message. The code was used as an example from the repository page. go version: go version go1.22.4 windows/amd64 Code: image

Debug log: ` "edited_message":{"message_id":106,"from":{"id":23432432,"is_bot":false,"first_name":"\u1160","username":"example_user","language_code":"en"},"chat":{"id":24234232,"first_name":"\u1160","username":"example_user","type":"private"},"date":1720134098,"edit_date":1720134108,"text":"/edit","entities":[{"offset":0,"length":5,"type":"bot_command"}]}}]}' panic: runtime error: invalid memory address or nil pointer dereference [signal 0xc0000005 code=0x0 addr=0x48 pc=0xb23a40]

goroutine 18 [running]: main.handler({0xc2d018, 0xc000068240}, 0xc0000000c0, 0xc0000b2000) C:/Users/anonymous/Desktop/bot/main.go:33 +0x40 github.com/go-telegram/bot.(Bot).ProcessUpdate.func1() C:/Users/anonymous/go/pkg/mod/github.com/go-telegram/bot@v1.5.0/process_update.go:25 +0x6d github.com/go-telegram/bot.(Bot).ProcessUpdate(0xc000287f78?, {0xc2d018?, 0xc000068240?}, 0x0?) C:/Users/anonymous/go/pkg/mod/github.com/go-telegram/bot@v1.5.0/process_update.go:36 +0xc3 github.com/go-telegram/bot.(Bot).waitUpdates(0xc0000000c0, {0xc2d018, 0xc000068240}, 0x0?) C:/Users/anonymous/go/pkg/mod/github.com/go-telegram/bot@v1.5.0/wait_updates.go:17 +0x85 created by github.com/go-telegram/bot.(Bot).Start in goroutine 1 C:/Users/anonymous/go/pkg/mod/github.com/go-telegram/bot@v1.5.0/bot.go:116 +0xa5 exit status 2 `

CodeExplorerX commented 4 days ago

Additions: When you restart the bot after a panic, panic occurs again and the bot cannot work. To eliminate panic, changing the token helps.

Debug log: 2024/07/05 01:17:11 [TGBOT] [DEBUG] request url: https://api.telegram.org/botexample/getMe, payload: null 2024/07/05 01:17:11 [TGBOT] [DEBUG] response from 'https://api.telegram.org/botexample/getMe' with payload '{"ok":true,"result":{"id":7159102647,"is_bot":true,"first_name":"kfmdskfms","username":"smdflksdmf_bot","can_join_groups":true,"can_read_all_group_messages":false,"supports_inline_queries":false,"can_connect_to_business":false}}' 2024/07/05 01:17:11 [TGBOT] [DEBUG] response from 'https://api.telegram.org/botexample/getUpdates' with payload '{"ok":true,"result":[{"update_id":78667351, "edited_message":{"message_id":106,"from":{"id":3423423,"is_bot":false,"first_name":"\u1160","username":"anonymous","language_code":"en"},"chat":{"id":3423423,"first_name":"\u1160","username":"anonymous","type":"private"},"date":1720134098,"edit_date":1720134108,"text":"/edit","entities":[{"offset":0,"length":5,"type":"bot_command"}]}}]}' panic: runtime error: invalid memory address or nil pointer dereference [signal 0xc0000005 code=0x0 addr=0x48 pc=0xd23a40]

goroutine 34 [running]: main.handler({0xe2d018, 0xc000068240}, 0xc0000000c0, 0xc0000fa000) C:/Users/anonymous/Desktop/bot/main.go:33 +0x40 github.com/go-telegram/bot.(Bot).ProcessUpdate.func1() C:/Users/anonymous/go/pkg/mod/github.com/go-telegram/bot@v1.5.0/process_update.go:25 +0x6d github.com/go-telegram/bot.(Bot).ProcessUpdate(0xc0000b7f78?, {0xe2d018?, 0xc000068240?}, 0x0?) C:/Users/anonymous/go/pkg/mod/github.com/go-telegram/bot@v1.5.0/process_update.go:36 +0xc3 github.com/go-telegram/bot.(Bot).waitUpdates(0xc0000000c0, {0xe2d018, 0xc000068240}, 0x0?) C:/Users/anonymous/go/pkg/mod/github.com/go-telegram/bot@v1.5.0/wait_updates.go:17 +0x85 created by github.com/go-telegram/bot.(Bot).Start in goroutine 1 C:/Users/anonymous/go/pkg/mod/github.com/go-telegram/bot@v1.5.0/bot.go:116 +0xa5 exit status 2