skip to Main Content

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


  1. Did you replace {YOUR_ACCESS_TOKEN_HERE} with your token? Until you do you’ll receive the Not 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:

    1. Send BotFather /newbot.
    2. Enter a bot name, this can be anything you want for display purposes.
    3. Enter a bot username, this has to be unique and must end in _bot.
    4. Copy the token from the message, and paste it into the code.

    Here’s a sample output you will receive after successfully setting up the bot: (removed sensitive info)

    Done! Congratulations on your new bot. You will find it at t.me/. You
    can now add a description, about section and profile picture for your
    bot, see /help for a list of commands. By the way, when you’ve
    finished creating your cool bot, ping our Bot Support if you want a
    better username for it. Just make sure the bot is fully operational
    before you do this.

    Use this token to access the HTTP API: {YOUR_ACCESS_TOKEN} Keep your
    token secure and store it safely, it can be used by anyone to control
    your bot.

    For a description of the Bot API, see this page: https://core.telegram.org/bots/api

    Login or Signup to reply.
  2. I now that it is too late but,guys, write NOT "{12312312411313123123}" BUT
    "12312312312312313". It worked!

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search