简体   繁体   English

C# Telegram.Bot SendTextMessageAsync 不发送任何消息

[英]C# Telegram.Bot SendTextMessageAsync dosen't send any messages

I'm trying to implement simple sending messages via telegram bot.我正在尝试通过电报机器人实现简单的发送消息。 Here is my code:这是我的代码:

using System;
using Telegram.Bot;
using Telegram.Bot.Types;

namespace ConsoleApp2
{

  class Program
  {
    public static string ApiKey { get; set; } = "MyApiKey";
    static void Main(string[] args)
    {
        TelegramBotClient client = new TelegramBotClient(ApiKey);
        client.SendTextMessageAsync(MyChatId, "Hello World");          
    }
  }
}

But this code dosen't send any message.但是此代码不会发送任何消息。 Any ideas?有任何想法吗?

SendTextMessageAsync method returns a Task . SendTextMessageAsync方法返回一个Task Try to await it.尝试等待它。

static async Task Main(string[] args)
{
    TelegramBotClient client = new TelegramBotClient(ApiKey);
    await client.SendTextMessageAsync(MyChatId, "Hello World");
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM