B
B
BadCats2018-03-26 23:02:45
C++ / C#
BadCats, 2018-03-26 23:02:45

Telegram bot OnMessage - doesn't remember input?

static void Main(string[] args)
    {

        botClient = new TelegramBotClient("token");
        var BotInformation = botClient.GetMeAsync().Result;
        botClient.StartReceiving();
        botClient.OnMessage += BotClient_OnMessage;



        Console.ReadLine();
        //botClient.StopReceiving();
        CountKey = 0;
    }

private async static void BotClient_OnMessage(object sender, Telegram.Bot.Args.MessageEventArgs e)
    {
        Program. args = e;

        switch (e.Message.Text)
        {
            case "/generate":
                My_messege = e.Message;
                Find_Path();

                break;
            case "/draw":
                My_messege = e.Message;
                StartGame();
                break;
            default:
                My_messege = e.Message;
                break;

        }

Call Find_Path(); in Find_Path(); I check what the user entered
if (wariant == "/left" && (LastID == 1 || LastID == 3 || LastID == 4))
        {
            s = "/left";
            s2 = "/right";
            await botClient.SendPhotoAsync(My_messege.Chat.Id, dd);// два пути  - лево - право
            goto check;
        }
        if (wariant == "/right" && LastID == 1 || LastID == 3 || LastID == 4)
        {
            s = "/right";
            s2 = "/left";
            await botClient.SendPhotoAsync(My_messege.Chat.Id, dd);// два пути  - лево - право
        }

- but before I get the variant value on the first call to Find_Path
if (C == 0)
        {
            await botClient.SendPhotoAsync(My_messege.Chat.Id, dd);
            await botClient.SendTextMessageAsync(My_messege.Chat.Id, s + " " + s2);
            wariant = args.Message.Text;
            C++;
            //вызвать BotClient_OnMessage
            Program.BotClient_OnMessage(botClient, args);

            return;
        }

in it, I must assign to the variant variable what the user entered - initializing it. But the BotClient_OnMessage method is not called when entering the second time after the bot is started. I thought that this is because now I am already in BotClient_OnMessage - in one of the cases and decided to try calling it manually, but this also does not help - even with manual re-call in the block switch (e.Message.Text)- the old value remains.

Answer the question

In order to leave comments, you need to log in

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question