gpt4 book ai didi

c# - 电报机器人 : GetUpdates Conflict

转载 作者:行者123 更新时间:2023-12-05 03:54:31 29 4
gpt4 key购买 nike

我使用此链接中的示例创建了测试 Telegram 机器人控制台应用程序 https://github.com/TelegramBots/Telegram.Bot.Examples

这是我的主要

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();
}

我在 Windows 10 上运行它 - 它工作正常。但是当我在 Windows 7 机器上运行它时,我收到异常:

Bot.Timeout= 00:01:40 Start listening for @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__541.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()

是什么原因,如何解决?

最佳答案

如评论所述;

: terminat ed by other getUpdates request; make sure that only one bot instance is running

表示同时调用了getUpdates()

为防止这种情况,要么停止其他机器人,要么创建一个将接收 web-hook 的机器人HTTP POST 更新请求。

在您告诉 Telegram 消息已被 getUpdate() offset 看到之前,您应该确保每条消息都由机器人处理。参数。

关于c# - 电报机器人 : GetUpdates Conflict,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/60881982/

29 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com