Telegram.Bot 包中未触发 OnMessage 事件
OnMessage event doesn't fire in Telegram.Bot package
您好专家 :) 我正在尝试在我的电报机器人收到消息时显示 MessageBox 。我使用了 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);
}
但是当我向我的机器人发送消息时它不显示消息框。
怎么了 ? :S
添加了一行代码就可以了:) :
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()
是开始收听新消息所需要的东西:)
请检查是否所有引用的库都是在 x64 或 AnyCPU 上构建的
我的解决方案中有一个 x86 项目,因此 OnMessage 没有触发。
您好专家 :) 我正在尝试在我的电报机器人收到消息时显示 MessageBox 。我使用了 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);
}
但是当我向我的机器人发送消息时它不显示消息框。 怎么了 ? :S
添加了一行代码就可以了:) :
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()
是开始收听新消息所需要的东西:)
请检查是否所有引用的库都是在 x64 或 AnyCPU 上构建的
我的解决方案中有一个 x86 项目,因此 OnMessage 没有触发。