public async Task Login() { var currentUser = Context.User; // Check to make sure the user is not already linked var alreadyLinkedUser = await database.Users .AsQueryable() .Where(x => x.DiscordId == currentUser.Id.ToString()) .FirstOrDefaultAsync(); if (alreadyLinkedUser != null) { await ReplyAsync( $@"{currentUser.Mention} your account is already linked with the email, {alreadyLinkedUser.Email}." + "If you would like to unlink you account you can use the `!unlink` command." ); return; } var linkKey = Guid.NewGuid().ToString().Replace("-", "") + Guid.NewGuid().ToString().Replace("-", ""); var discordId = currentUser.Id; var discordLink = new DiscordLink() { DiscordId = discordId.ToString(), LinkKey = linkKey }; database.Add(discordLink); await database.SaveChangesAsync(); await ReplyAsync($"{currentUser.Mention} a direct message has been sent with further instructions for setting up your account."); await currentUser.SendMessageAsync( "Please login to your NTime account using the following link to link your discord account to your NTime account " + configuration["WebsiteLink"] + "auth/login?discordLink=" + linkKey ); }