如何在C#中处理Telegram bot上的多个用户?
内容导读
互联网集市收集整理的这篇技术教程文章主要介绍了如何在C#中处理Telegram bot上的多个用户?,小编现在分享给大家,供广大互联网技能从业者学习和参考。文章包含2345字,纯文字阅读大概需要4分钟。
内容图文
![如何在C#中处理Telegram bot上的多个用户?](/upload/InfoBanner/zyjiaocheng/820/78dc764e7b13401f935bb87149ddff28.jpg)
我写了一个机器人,询问你的名字并将其写在照片上并发送给你并且它有效.但问题是机器人上有多个用户
它不起作用和崩溃,我想知道如何分离用户条目和输出.(就像每个连接的用户得到一个单独的会话,因为现在一切都发生在一个会话中,它崩溃)
这是我的代码:
void bot_OnMessage(object sender, Telegram.Bot.Args.MessageEventArgs e)
{
KeyboardButton[] btns = new KeyboardButton[1];
btns[0] = new KeyboardButton("???? ???");
if(e.Message.Text=="???? ???")
{
bot.SendTextMessageAsync(e.Message.From.Id, "??? ??? ?? ???? ????", Telegram.Bot.Types.Enums.ParseMode.Default, false, false, 0);
// e.Message.Text = null;
shart = 1;
}
else
{
if (shart == 0)
{
Telegram.Bot.Types.ReplyMarkups.ReplyKeyboardMarkup markup = new Telegram.Bot.Types.ReplyMarkups.ReplyKeyboardMarkup(btns);
bot.SendTextMessageAsync(e.Message.From.Id, "???? ???? ? ???? ??? ??? ???? ???? ??? ???? ????", Telegram.Bot.Types.Enums.ParseMode.Default, false, false, 0, markup);
}
if (shart==1)
{
bot.StartReceiving();
bot.OnMessage += bot_OnMessage1;
}
}
}
void bot_OnMessage1(object sender, Telegram.Bot.Args.MessageEventArgs a)
{
string watermarkText = a.Message.Text;
//Get the file name.
string fileName = "C:\\temp\\01.jpg";
//Read the File into a Bitmap.
using (Bitmap bmp = new Bitmap(fileName))
{
using (Graphics grp = Graphics.FromImage(bmp))
{
//Set the Color of the Watermark text.
Brush brush = new SolidBrush(Color.White);
//Set the Font and its size.
Font font = new System.Drawing.Font("Arial", 50, FontStyle.Bold, GraphicsUnit.Pixel);
//Determine the size of the Watermark text.
SizeF textSize = new SizeF();
textSize = grp.MeasureString(watermarkText, font);
//Position the text and draw it on the image.
Point position = new Point((bmp.Width - ((int)textSize.Width + 10)), (bmp.Height - ((int)textSize.Height + 10)));
grp.DrawString(watermarkText, font, brush, position);
bmp.Save("c:\\temp\\postpic.jpg", ImageFormat.Png);
using (FileStream fs = new FileStream("c:\\temp\\postpic.jpg", FileMode.Open))
{
fs.CanTimeout.ToString();
FileToSend fileToSend = new FileToSend("postpic.jpg", fs);
// var = FileToSend fts = new FileToSend("postpic", fs);
var rep = bot.SendPhotoAsync(a.Message.From.Id, fileToSend, "??? ??? ?? ??? ????").Result;
}
}
}
}
}
解决方法:
您正在为每个用户编写(并随后读取)相同的文件:
mp.Save("c:\\temp\\postpic.jpg"
您需要为每个用户提供唯一的文件名.或者更好的是,根本不要使用文件.您可能只是使用本地内存流而根本不会使用文件混乱磁盘.
内容总结
以上是互联网集市为您收集整理的如何在C#中处理Telegram bot上的多个用户?全部内容,希望文章能够帮你解决如何在C#中处理Telegram bot上的多个用户?所遇到的程序开发问题。 如果觉得互联网集市技术教程内容还不错,欢迎将互联网集市网站推荐给程序员好友。
内容备注
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 gblab@vip.qq.com 举报,一经查实,本站将立刻删除。
内容手机端
扫描二维码推送至手机访问。