B
B
Bream23192020-07-13 14:09:09
C++ / C#
Bream2319, 2020-07-13 14:09:09

Telegram Bot C# does not work when I do it in windows form, there are no problems in the console version. What exactly am I doing wrong?

It compiles without errors, but there is no response from the bot
using Telegram.Bot;
using Telegram.Bot.Args;

namespace testnew1
{

public partial class Form1 : Form
{
private static readonly TelegramBotClient Bot = new TelegramBotClient("1112830625:AAFJY9nzP-heIxj10G2JYQUVcMu8vSvnEB0");

public Form1()
{
InitializeComponent();
Bot.OnMessage += Bot_OnMessage;
Bot.OnMessageEdited += Bot_OnMessage;
Bot.StartReceiving();
Bot.StopReceiving();

}
private static void Bot_OnMessage(object sender, Telegram.Bot.Args.MessageEventArgs e)
{
if (e.Message.Type == Telegram.Bot.Types.Enums.MessageType.Text)
{
if (e.Message.Text == "test")
Bot.SendTextMessageAsync(e.Message.Chat.Id, "test_response ");
else if (e.Message.Text == "test_2")
{
Bot.SendTextMessageAsync(e.Message.Chat.Id, "test_response_2_name" + e.Message.Chat.Username);
}
else
{
Bot.SendTextMessageAsync(e.Message.Chat.Id, @"command error");
}
}
}

Answer the question

In order to leave comments, you need to log in

1 answer(s)
B
Bream2319, 2020-07-15
@Bream2319

Added:
using System.Net;
and
InitializeComponent();
ServicePointManager.SecurityProtocol = SecurityProtocolType.Tls12;
And everything started

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question