Telegram Bot API sendMessage returns 400 error

I’m working on a personal bot library and having trouble with the sendMessage method from Telegram’s Bot API. I created a channel called “test_channel456” and my username is “test_user456”. I’m the admin and only member of this channel.

Whenever I try to send messages to my channel or directly to myself through the bot, I keep getting a Bad request 400 error. Here’s what I’m attempting:

bot.send_message(chat_id="@test_channel456", text="hello world")

# alternatively
bot.send_message(chat_id="@test_user456", text="hello world")

# or combined
bot.send_message(chat_id="@test_channel456test_user456", text="hello world")

I suspect the issue is with how I’m formatting the chat_id parameter. Are any of these approaches correct for referencing a channel or username? My other API methods work fine so the bot credentials are definitely valid.

The @ symbol works fine with usernames and channel names in Telegram Bot API. Your real problem is probably that the bot isn’t added as an admin with posting permissions on your channel. Even though you created the channel, you still need to explicitly add the bot as admin. Go to channel settings, add your bot as admin, and make sure “Post Messages” is enabled. For DMs to yourself - the bot can only message you if you’ve started a conversation with it first. Bots can’t initiate conversations due to Telegram’s privacy rules. Message your bot directly first, then use your numeric user ID instead of the username.

try using the actual channel ID instead of the username. you can get it by forwarding a msg to @userinfobot or checking the getUpdates response. also, avoid the @ symbol in the chat_id, it might be causing the issue.

The @test_channel456test_user456 format is definitely wrong - that’s not valid. For channels, your bot needs admin rights with message posting permissions, or you’ll get 400 errors even with correct formatting. @test_channel456 should work if permissions are right, but I’ve found numerical IDs way more reliable than usernames. Want the channel ID? Send a test message to the channel manually, then call getUpdates on your bot - the channel ID shows up in the response. For personal messages, the bot needs an existing conversation thread with you before it can send anything.