本文介绍了我想在C#中的win form应用程序中使用botsharp库的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想在C#中的win form应用程序中使用botsharp库来使用电报机器人

但我要面对这个错误

('消息'是一个模糊的参考在'System.Windows.Forms.Message'和'TelegramBotSharp.Types.Message'之间)









foreach(结果中的消息m)



private static void ControlMessages1(消息m)



我尝试了什么:



i want to use botsharp library in win form application in C# for use telegram bot
but i To face whith this error
( 'Message' is an ambiguous refrence between 'System.Windows.Forms.Message' and 'TelegramBotSharp.Types.Message')




foreach (Message m in result)
and
private static void ControlMessages1(Message m)

What I have tried:

using System;
using System.Threading.Tasks;
using System.Windows.Forms;
using TelegramBotSharp;
using TelegramBotSharp.Types;
namespace WindowsFormsApplication1
{
    public partial class Form1 : Form
    {
        public static TelegramBot bot;
        public Form1()
        {
            InitializeComponent();


        }

        private void button1_Click(object sender, EventArgs e)
        {
            bot = new TelegramBot("146900***********************-FyoSPg");
             new Task(PollMessages1).Start();
        }

        static async void PollMessages1()
        {
            while (true)
            {
                var result = await bot.GetMessages();
                foreach (Message m in result)
                {
                    if (m.Chat != null)
                    {
                        Console.WriteLine("[{0}] {1} : {2}", m.Chat.Title, m.From.Username, m.Text);
                    }
                    else
                    {
                        Console.WriteLine("{0}: {1}", m.From.Username, m.Text);
                    }
                    ControlMessages1(m);
                }

            }
        }

        private static void ControlMessages1(Message m)
        {
            if (m.Text == null) return;
            MessageTarget target = (MessageTarget)m.Chat ?? m.From;

                bot.SendMessage(target, "hello");
         }
    }
}

推荐答案


这篇关于我想在C#中的win form应用程序中使用botsharp库的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-15 10:42