StarAssassin64 0 Posted January 13 Share Posted January 13 So, I am working on a discord bot for my VTC, which we want on the commands to get the TMP server stats. We have the location for the API, and when we do the print command (we are using discord.py) It'll print all the server stats, but once I get it to send the messages, It'll only get the information about the last server. Is there a way where I can get it to give all the information like the print command. Link to post Share on other sites
ASIR [CZE] 750 Posted January 13 Share Posted January 13 Hi, I think you will be more successful with your question in this section: https://forum.truckersmp.com/index.php?/forum/198-developer-portal/ Best Regards //ASIR Link to post Share on other sites
Snap Dragon 1101 Posted Thursday at 08:05 AM Share Posted Thursday at 08:05 AM Moved to Developer Portal Link to post Share on other sites
VSOUSA14 24 Posted Monday at 10:09 AM Share Posted Monday at 10:09 AM Hello. I never used python, but you can try to create getters and then use an array where you get the getters and the response from server, and then make a loop to print all the servers: Something like this (This code below is in C#) <!--CLASS THAT HANDLES THE HTTP REQUEST--> public void UpdateServerInfo() { svCon = "http://" + ipSRV + "/players.json"; WebRequest request = WebRequest.Create(svCon); request.Credentials = CredentialCache.DefaultCredentials; ipServ = isExist(svCon); if (ipServ) { WebResponse response = request.GetResponse(); status = ((HttpWebResponse)response).StatusDescription; Console.WriteLine(status); using (Stream dataStream = response.GetResponseStream()) { StreamReader reader = new StreamReader(dataStream); responseFromServer = reader.ReadToEnd(); Console.WriteLine(responseFromServer); } response.Close(); label2.Text = "Online"; listBox1.Visible = true; panel3.BackColor = Color.LawnGreen; <!-- SEE BELOW THIS --> Player[] item = JsonConvert.DeserializeObject<Player[]>(responseFromServer); var countPlayers = item.Count(); label1.Text = countPlayers.ToString() + " Online Players"; listBox1.Items.Clear(); foreach (Player name in item) listBox1.Items.Add(" "+name.name); listBox1.Items.Add(""); <!-- SEE ABOVE THIS --> } else { label2.Text = "Offline"; panel3.BackColor = Color.Red; label1.Text = "Visit our discord our teamspeak for more information"; button2.Visible = false; listBox1.Visible = false; panel4.Visible = false; label4.Visible = false; } } <!--//GETTER--> public class Player { public string endpoint { get; set; } public int id { get; set; } public string[] identifiers { get; set; } public string name { get; set; } public int ping { get; set; } } In this C# programm, i am printing out each player into a listBox. In your Discord bot you can make something similar. Link to post Share on other sites
Recommended Posts