Итак, у меня есть некоторый код, который запишет текущий DateTime в текстовый файл, а затем опубликует некоторые встраивания, если текстовый файл не существует. Если это произойдет, то он будет читать файл, проверить, была ли дата в файле более 1 минуты назад, если это было так, он должен отправить ту же самую вставку, что и файл, который создает файл, если это не было 1 минуту, то он отправит код для вставки, который будет ждать вас.
По какой-то причине аспект создания и отправки работает нормально, но если я снова запускаю команду, когда она пытается преобразовать строку в DateTime, происходит сбой, говоря «String не был распознан как действительный DateTime». Я проверил несколько веб-сайтов, и формат даты и времени, который я использую, правильный. Есть идеи?
string FilePath22 = Environment.CurrentDirectory + "/servers/" + Context.Guild.Id + ".txt";
string FilePath = Environment.CurrentDirectory + "/descriptions/" + Context.Guild.Id + ".txt";
string FilePath2 = Environment.CurrentDirectory + "/invites/" + Context.Guild.Id + ".txt";
var chnl = Context.Client.GetChannel(511281184760791056) as ITextChannel;
string invitelink = System.IO.File.ReadAllText(FilePath2);
string desclink = System.IO.File.ReadAllText(FilePath);
var builder2 = new EmbedBuilder()
.WithColor(Color.Orange)
.WithAuthor(Context.Guild.Name)
.WithThumbnailUrl(Context.Guild.IconUrl)
.WithUrl(invitelink)
.AddField("Information", "**Owner:** " + Context.Guild.Owner + Environment.NewLine +
"**Description:** " + Environment.NewLine + Environment.NewLine + desclink + Environment.NewLine + Environment.NewLine + "**Invite:** " + invitelink)
.AddField("Other Info", "**Members:** " + Context.Guild.MemberCount + Environment.NewLine + "**Emotes:** " + Context.Guild.Emotes.Count + Environment.NewLine + "**Roles:** " + Context.Guild.Roles.Count + Environment.NewLine + "**Created At:** " + Context.Guild.CreatedAt.Date);
var embed2 = builder2.Build();
await chnl.SendMessageAsync(embed: embed2);
var builder44 = new EmbedBuilder()
.WithColor(Color.Orange)
.WithTitle("Server Bumped!");
var embed44 = builder44.Build();
if (!File.Exists(FilePath22))
{
await ReplyAsync(embed: embed44);
System.IO.File.WriteAllText(FilePath22, DateTime.Now.ToString("MM/dd/yyyy HH:mm:ss", CultureInfo.InvariantCulture));
return;
}
string readit = System.IO.File.ReadAllText(FilePath22);
Console.WriteLine(readit);
var converted = DateTime.Parse(readit); //problem
Console.WriteLine(converted);
if (HoursPassed(converted))
{
await ReplyAsync(embed: embed44);
System.IO.File.WriteAllText(FilePath22, DateTime.Now.ToString("MM/dd/yyyy HH:mm:ss", CultureInfo.InvariantCulture));
return;
}
var builder10 = new EmbedBuilder()
.WithColor(Color.Orange)
.WithTitle("You must wait 24 hours before bumping your server! Try again later.");
var embed10 = builder10.Build();
await ReplyAsync(embed: embed10);