Answer the question
In order to leave comments, you need to log in
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
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question