[英]OnMessage event doesn't fire in Telegram.Bot package
Hi experts :) I'm trying to show a MessageBox whenever my telegram bot receives a message .嗨专家:) 每当我的电报机器人收到消息时,我都会尝试显示一个 MessageBox 。 I have used Telegram.Bot package and written these codes :
我使用了 Telegram.Bot 包并编写了这些代码:
TelegramBotClient Bot = new TelegramBotClient("MyToken");
public Form1()
{
InitializeComponent();
}
private void Form1_Load(object sender, EventArgs e)
{
Bot.OnMessage += Bot_OnMessage;
Bot.OnUpdate += Bot_OnUpdate;
}
private void Bot_OnMessage(object sender, Telegram.Bot.Args.MessageEventArgs e)
{
MessageBox.Show(e.Message.Text);
}
private void Bot_OnUpdate(object sender, Telegram.Bot.Args.UpdateEventArgs e)
{
var botClient = (TelegramBotClient)sender;
MessageBox.Show(e.Update.Message.Text);
}
but it doesn't show messagebox when I send a message to my bot .但是当我向我的机器人发送消息时它不显示消息框。 What's the matter ?
怎么了? :S
:S
A line of code added and it works :) :添加了一行代码,它可以工作:):
TelegramBotClient Bot = new TelegramBotClient("MyToken");
public Form1()
{
InitializeComponent();
}
private void Form1_Load(object sender, EventArgs e)
{
Bot.StartReceiving();
Bot.OnMessage += Bot_OnMessage;
}
private void Bot_OnMessage(object sender, Telegram.Bot.Args.MessageEventArgs e)
{
MessageBox.Show(e.Message.Text);
}
Bot.StartReceiving()
was the thing that was needed to start listening for new messages :) Bot.StartReceiving()
是开始侦听新消息所需的东西:)
Please check out if all referenced libraries are build on x64 or AnyCPU请检查所有引用的库是否构建在 x64 或 AnyCPU 上
I had a x86 project in my solution and therefore the OnMessage was not firing.我的解决方案中有一个 x86 项目,因此 OnMessage 没有触发。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.