简体   繁体   English

电报机器人:GetUpdates 冲突

[英]Telegram bot: GetUpdates Conflict

I have created the test Telegram bot console app using sample from this link https://github.com/TelegramBots/Telegram.Bot.Examples我使用此链接中的示例创建了测试 Telegram bot 控制台应用程序https://github.com/TelegramBots/Telegram.Bot.Examples

There is my main有我的主要

public static async Task Main()
{
    ServicePointManager.Expect100Continue = true;
    ServicePointManager.SecurityProtocol = SecurityProtocolType.Tls12;
    Bot = new TelegramBotClient(Configuration.BotToken);
    var me = await Bot.GetMeAsync();
    Console.Title = me.Username;

    var cts = new CancellationTokenSource();

    // StartReceiving does not block the caller thread. Receiving is done on the ThreadPool.
    Console.WriteLine($"Bot.Timeout= {Bot.Timeout}");

    //Bot.Timeout = TimeSpan.FromMilliseconds(30000);
    Bot.StartReceiving(
        new DefaultUpdateHandler(HandleUpdateAsync, HandleErrorAsync),
        cts.Token
    );

    Console.WriteLine($"Start listening for @{me.Username}");

    Console.ReadLine();

    // Send cancellation request to stop bot
    cts.Cancel();
}

I run it on Windows 10 - it works fine.我在 Windows 10 上运行它 - 它工作正常。 But when I run it on the Windows 7 machine I receive the exception:但是当我在 Windows 7 机器上运行它时,我收到异常:

Bot.Timeout= 00:01:40 Start listening for @my123_bot HandleErrorAsync Telegram.Bot.Exceptions.ApiRequestException: Conflict: terminat ed by other getUpdates request; Bot.Timeout= 00:01:40 开始监听@my123_bot HandleErrorAsync Telegram.Bot.Exceptions.ApiRequestException: Conflict: terminat ed by other getUpdates request; make sure that only one bot instance is running at Telegram.Bot.TelegramBotClient.d__54 1.MoveNext() --- End of stack trace from previous location where exception was thrown --- at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task) at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNot ification(Task task) at Telegram.Bot.TelegramBotClientPollingExtensions.<ReceiveAsync>d__3.MoveNex t() HandleErrorAsync Telegram.Bot.Exceptions.ApiRequestException: Conflict: terminat ed by other getUpdates request; make sure that only one bot instance is running at Telegram.Bot.TelegramBotClient.<MakeRequestAsync>d__54确保只有一个机器人实例在 Telegram.Bot.TelegramBotClient.d__54 上运行1.MoveNext() --- End of stack trace from previous location where exception was thrown --- at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task) at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNot ification(Task task) at Telegram.Bot.TelegramBotClientPollingExtensions.<ReceiveAsync>d__3.MoveNex t() HandleErrorAsync Telegram.Bot.Exceptions.ApiRequestException: Conflict: terminat ed by other getUpdates request; make sure that only one bot instance is running at Telegram.Bot.TelegramBotClient.<MakeRequestAsync>d__54 1.MoveNext() --- End of stack trace from previous location where exception was thrown --- at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task) at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNot ification(Task task) at Telegram.Bot.TelegramBotClientPollingExtensions.<ReceiveAsync>d__3.MoveNex t() HandleErrorAsync Telegram.Bot.Exceptions.ApiRequestException: Conflict: terminat ed by other getUpdates request; make sure that only one bot instance is running at Telegram.Bot.TelegramBotClient.<MakeRequestAsync>d__54 1.MoveNext() --- End of stack trace from previous location where exception was thrown --- at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task) at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNot ification(Task task) at Telegram.Bot.TelegramBotClientPollingExtensions.d__3.MoveNex t() 1.MoveNext() --- End of stack trace from previous location where exception was thrown --- at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task) at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNot ification(Task task) at Telegram.Bot.TelegramBotClientPollingExtensions.<ReceiveAsync>d__3.MoveNex t() HandleErrorAsync Telegram.Bot.Exceptions.ApiRequestException: Conflict: terminat ed by other getUpdates request; make sure that only one bot instance is running at Telegram.Bot.TelegramBotClient.<MakeRequestAsync>d__54 1.MoveNext() --- 从上一个抛出异常的位置结束堆栈跟踪 --- 在 System.Runtime.CompilerServices.TaskAwaiter .ThrowForNonSuccess(Task task) at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task) at Telegram.Bot.TelegramBotClientPollingExtensions.d__3.MoveNex t()

What is the reason and how to fix it?是什么原因以及如何解决?

As described in the comments;如评论中所述;

: terminat ed by other getUpdates request; : 被其他 getUpdates 请求终止; make sure that only one bot instance is running确保只有一个机器人实例正在运行

Indicates that getUpdates() is being called at the same time.表示同时调用getUpdates()

To prevent this, either stop the other bots, or create a bot that will receive a web-hook HTTP POST request on update.为防止出现这种情况,请停止其他机器人,或创建一个机器人,该机器人将在更新时接收网络钩子HTTP POST请求。

You should ensure that each message is handled by the bot(s) before you tell Telegram the message has been seen by the getUpdate() offset param.在您告诉 Telegram 消息已经被getUpdate()偏移参数看到之前,您应该确保每条消息都由机器人处理。

make sure that only one bot instance is running确保只有一个机器人实例正在运行

I was able to solve this problem by revoking and updating bot token.我能够通过撤销和更新机器人令牌来解决这个问题。 This worked because I think it stopped all the bot instances that were using the old token.这是有效的,因为我认为它停止了所有使用旧令牌的机器人实例。

I solved this problem with rebooting my PC.我通过重新启动 PC 解决了这个问题。 I guess problem appears because the processes we cant see and rebooting just stops them down我想问题出现是因为我们看不到的进程和重新启动只会停止它们

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

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