I’m trying to write a bot for Telegram on C#.
I tried some basic syntax, the program is primitive:
using Telegram.Bot;
var botClient = new TelegramBotClient("{YOUR_ACCESS_TOKEN_HERE}");
var me = await botClient.GetMeAsync();
Console.WriteLine($"Hello, World! I am user {me.Id} and my name is {me.FirstName}.");
Then when I’m running the code the Debug Console outputs the following:
Unhandled exception. Telegram.Bot.Exceptions.ApiRequestException: Not
Found at
Telegram.Bot.TelegramBotClient.MakeRequestAsync[TResponse](IRequest`1
request, CancellationToken cancellationToken) at
Telegram.Bot.TelegramBotClientExtensions.GetMeAsync(ITelegramBotClient
botClient, CancellationToken cancellationToken) at
Program.$(String[] args) in
D:ProjectsMy_BotMy_BotProgram.cs:line 5 at
Program.(String[] args)
While the error list is empty.
How can I get rid of this exception and get a proper output?
Thanks in advance.
2
Answers
Did you replace
{YOUR_ACCESS_TOKEN_HERE}
with your token? Until you do you’ll receive theNot Found
exception. If you did, then you may want to validate that you have a valid token.If you haven’t got a token, you can get one by messaging the BotFather on telegram. It’s a bot designed by Telegram to help you through the process.
Here’s the documentation from Telegram on setting up everything. https://core.telegram.org/bots
EDIT
To use BotFather:
/newbot
._bot
.Here’s a sample output you will receive after successfully setting up the bot: (removed sensitive info)
For a description of the Bot API, see this page: https://core.telegram.org/bots/api
I now that it is too late but,guys, write NOT "{12312312411313123123}" BUT
"12312312312312313". It worked!