Emily Posted April 30, 2020 Report Posted April 30, 2020 (edited) solved. Edited May 18, 2020 by Emily Quote
vrtgn Posted May 1, 2020 Report Posted May 1, 2020 Check if the incoming message is only from those "group members" by using their steam ID 64. Quote
Emily Posted May 1, 2020 Author Report Posted May 1, 2020 12 hours ago, vrtgn said: Check if the incoming message is only from those "group members" by using their steam ID 64. can you code sample? For example, I want to use the !help command only by people who are members of the group. Quote
vrtgn Posted May 1, 2020 Report Posted May 1, 2020 let groupMembers = [""] // an array containing steamid64's as strings of those group members client.on('friendMessage', (steamID, message) => { if (groupMembers.includes(steamID.getSteamID64())) { // code here } }) Alternatively you could ensure that the only people that can add the bot are the group members and then you wouldn't need the if statement. You may also want to get the group members using some method as if there are new ones you will have to add them manually and for convenience you should store their SteamID64 values in a file, perhaps a .json. Quote
Emily Posted May 1, 2020 Author Report Posted May 1, 2020 I want to use the contacts in groupID, not the steam ID of the people in my group. Quote
Emily Posted May 1, 2020 Author Report Posted May 1, 2020 client.on("friendMessage", function(steamID, message) { if (message == "!help") { //code } } else if (message == "!info") { I want to do I want only the members of the group to use the !help command. I want people who are not members of the group to send a "you must be a member of the group" message Quote
vrtgn Posted May 1, 2020 Report Posted May 1, 2020 You want to get the Chat Room Group State of the group, which has a property of members containing an array of Chat Room Member. You could map the SteamID of those members to a single array and check if the sender of the message is included in the mapped array. Quote
Emily Posted May 1, 2020 Author Report Posted May 1, 2020 I'm sorry I couldn't understand what you said not a steam chat room group people who add the steam bot must be a member of the group to use all commands @vrtgn and, i want people who are not members of the group to send a "you must be a member of the group" message it starts like this client.on("friendMessage", function(steamID, message) { if (message == "!help") { client.chatMessage(steamID, "message); } } else if (message == "!info") { client.chatMessage(steamID, "message"); .. .. .. how can i add as i said? please help me Quote
xLeeJYx Posted May 3, 2020 Report Posted May 3, 2020 use getSteamGroup to get the group details and then getMembers to get the steamids of the members in your group. You can store the array somewhere in the code or anywhere u want it. Then check if the id is present in that array when a message is received Quote
Emily Posted May 5, 2020 Author Report Posted May 5, 2020 On 5/3/2020 at 11:10 AM, xLeeJYx said: use getSteamGroup to get the group details and then getMembers to get the steamids of the members in your group. You can store the array somewhere in the code or anywhere u want it. Then check if the id is present in that array when a message is received how can i do that can you help me please i need it @xLeeJYx Quote
Perport Posted May 11, 2020 Report Posted May 11, 2020 (edited) const steamCommunity = require('steamcommunity'); const client = new steamUser(); let community = new SteamCommunity(); let groupmembers; // https://steamcommunity.com/groups/reddit 's group name would be "reddit" as a string // call getGroup on your code on client loggedOn event or somewhere else you want function getGroup(groupName) { community.getSteamGroup(groupName, (err, group) => { if (err) { console.log("Couldn't get the Group Retrying"); setTimeout(getGroup, 5000); } else group.getMembers((err, members) => { if (err) { console.log("Couldn't get the Group Retrying.."); setTimeout(getGroup, 5000); } else { groupmembers = members; } }); }); } client.on("friendMessage", (steamID,msg) => { if(groupmembers.includes(steamID.getSteamID64())){ //do your thing } else client.chatMessage(steamID,"You have to join our steam group bla bla to use this bot or idk"); }); this should work if you still have problems please let me know Edited May 11, 2020 by Perport Quote
Emily Posted May 11, 2020 Author Report Posted May 11, 2020 12 hours ago, Perport said: const steamCommunity = require('steamcommunity'); const client = new steamUser(); let community = new SteamCommunity(); let groupmembers; // https://steamcommunity.com/groups/reddit 's group name would be "reddit" as a string // call getGroup on your code on client loggedOn event or somewhere else you want function getGroup(groupName) { community.getSteamGroup(groupName, (err, group) => { if (err) { console.log("Couldn't get the Group Retrying"); setTimeout(getGroup, 5000); } else group.getMembers((err, members) => { if (err) { console.log("Couldn't get the Group Retrying.."); setTimeout(getGroup, 5000); } else { groupmembers = members; } }); }); } client.on("friendMessage", (steamID,msg) => { if(groupmembers.includes(steamID.getSteamID64())){ //do your thing } else client.chatMessage(steamID,"You have to join our steam group bla bla to use this bot or idk"); }); this should work if you still have problems please let me know Cannot read property 'includes' of undefined Quote
Perport Posted May 11, 2020 Report Posted May 11, 2020 8 minutes ago, Emily said: Cannot read property 'includes' of undefined Did you call the getGroup function ? Like client.on("loggedOn",()=>{ getGroup("reddit"); } Quote
Emily Posted May 12, 2020 Author Report Posted May 12, 2020 2 hours ago, Perport said: Did you call the getGroup function ? Like client.on("loggedOn",()=>{ getGroup("reddit"); } if(groupmembers.includes(steamID.getSteamID64())){ I'm still getting this error :( Cannot read property 'includes' of undefined client.on('loggedOn', () => { getGroup("mygroupname"); client.setPersona(SteamUser.EPersonaState.LookingToTrade); client.gamesPlayed(["Test Bot",730]); }); let groupmembers; function getGroup(groupName) { community.getSteamGroup(groupName, (err, group) => { if (err) { console.log("Couldn't get the Group Retrying"); setTimeout(getGroup, 5000); } else group.getMembers((err, members) => { if (err) { console.log("Couldn't get the Group Retrying.."); setTimeout(getGroup, 5000); } else { groupmembers = members; } }); }); } client.on("friendMessage", function(steamID, message) { if (message == "!test") { if(groupmembers.includes(steamID.getSteamID64())){ client.chatMessage(steamID, "Test Message"); } else client.chatMessage(steamID,"You have to join our steam group bla bla to use this bot or idk"); }}) I did it this way but I get the error I said Quote
Perport Posted May 12, 2020 Report Posted May 12, 2020 5 hours ago, Emily said: if(groupmembers.includes(steamID.getSteamID64())){ I'm still getting this error Cannot read property 'includes' of undefined client.on('loggedOn', () => { getGroup("mygroupname"); client.setPersona(SteamUser.EPersonaState.LookingToTrade); client.gamesPlayed(["Test Bot",730]); }); let groupmembers; function getGroup(groupName) { community.getSteamGroup(groupName, (err, group) => { if (err) { console.log("Couldn't get the Group Retrying"); setTimeout(getGroup, 5000); } else group.getMembers((err, members) => { if (err) { console.log("Couldn't get the Group Retrying.."); setTimeout(getGroup, 5000); } else { groupmembers = members; } }); }); } client.on("friendMessage", function(steamID, message) { if (message == "!test") { if(groupmembers.includes(steamID.getSteamID64())){ client.chatMessage(steamID, "Test Message"); } else client.chatMessage(steamID,"You have to join our steam group bla bla to use this bot or idk"); }}) I did it this way but I get the error I said I justed tested it on a bigger group. It takes about a minute or so to load it so I though printing it to a console would help. Made the groupmembers var array from the beginning so it won't give you an error when someone types while it's still loading. Fixed few things about what bot does when it fails to get the group or its members. And made the array keep their accountids instead of steamid objects. Here is the code : client.on('loggedOn', () => { console.log("LoggedOn"); getGroup("yourgroupname"); client.setPersona(SteamUser.EPersonaState.LookingToTrade); client.gamesPlayed(["Test Bot", 730]); }); let groupmembers = []; function getGroup(groupName) { community.getSteamGroup(groupName, (err, group) => { if (err) { console.log("Couldn't get the Group Retrying"); setTimeout((groupName) => { getGroup(groupName) }, 5000); } else group.getMembers((err, members) => { if (err) { console.log("Couldn't get the Group Retrying.."); setTimeout((groupName) => { getGroup(groupName) }, 5000); } else { members.forEach(member => { groupmembers.push(member.accountid); }); console.log("Loaded The Group Members"); } }); }); } client.on("friendMessage", function (steamID, message) { if (groupmembers.length > 0) { if (message == "!test") { if (groupmembers.includes(steamID.accountid)) { client.chatMessage(steamID, "Test Message"); } else client.chatMessage(steamID, "You have to join our steam group bla bla to use this bot or idk"); } } else { client.chatMessage(steamID, "bot is still loading message"); } }); If you still have problems or questions feel free to ask Emily 1 Quote
Emily Posted May 12, 2020 Author Report Posted May 12, 2020 Thank you man how long have I been looking for this code now the person who is a member of the group is using it, but there is another problem, when this person leaves the group, he still continues to use that command. @Perport and I can't use this command after joining the group Quote
Perport Posted May 12, 2020 Report Posted May 12, 2020 2 hours ago, Emily said: Thank you man how long have I been looking for this code now the person who is a member of the group is using it, but there is another problem, when this person leaves the group, he still continues to use that command. @Perport and I can't use this command after joining the group Then calling the getgroup function everytime someone messages you would help but probably slow down the response time but if you want to do it then this should work. And you can remove the getGroup from loggedOn event. function getGroup(groupName,callback) { groupmembers = []; community.getSteamGroup(groupName, (err, group) => { if (err) { console.log("Couldn't get the Group Retrying"); setTimeout((groupName) => { getGroup(groupName,callback) }, 5000); } else group.getMembers((err, members) => { if (err) { console.log("Couldn't get the Group Retrying.."); setTimeout((groupName) => { getGroup(groupName,callback) }, 5000); } else { members.forEach(member => { groupmembers.push(member.accountid); }); callback(groupmembers); console.log("Loaded The Group Members"); } }); }); } client.on("friendMessage", function (steamID, message) { getGroup("yourGroupName",members => { if (members.length > 0) { if (message == "!test") { if (members.includes(steamID.accountid)) { client.chatMessage(steamID, "Test Message"); } else client.chatMessage(steamID, "You have to join our steam group bla bla to use this bot or idk"); } } else { client.chatMessage(steamID, "bot is still loading message"); } }); }); Quote
Emily Posted May 13, 2020 Author Report Posted May 13, 2020 ReferenceError: members is not defined Quote
Emily Posted May 13, 2020 Author Report Posted May 13, 2020 ok ReferenceError: members is not defined i solved your mistake my current problem is that I want one command to use only group member, doesn't recognize other commands Quote
Perport Posted May 13, 2020 Report Posted May 13, 2020 6 hours ago, Emily said: ok ReferenceError: members is not defined i solved your mistake my current problem is that I want one command to use only group member, doesn't recognize other commands I couldn't get that can you explain a little more ? Quote
Emily Posted May 13, 2020 Author Report Posted May 13, 2020 so i mean function getGroup(groupName,callback) { groupmembers = []; community.getSteamGroup(groupName, (err, group) => { if (err) { console.log("Couldn't get the Group Retrying"); setTimeout((groupName) => { getGroup(groupName,callback) }, 5000); } else group.getMembers((err, members) => { if (err) { console.log("Couldn't get the Group Retrying.."); setTimeout((groupName) => { getGroup(groupName,callback) }, 5000); } else { members.forEach(member => { groupmembers.push(member.accountid); }); callback(groupmembers); console.log("Loaded The Group Members"); } }); }); } client.on("friendMessage", function (steamID, message) { getGroup("mygroupname",members => { if (members.length > 0) { if (message == "!test") { if (members.includes(steamID.accountid)) { client.chatMessage(steamID, "Test Message"); } else client.chatMessage(steamID, "You have to join our steam group"); } } else { client.chatMessage(steamID, "bot is still loading message"); } } else if (message == "!help") { client.chatMessage(steamID, "Test Message"); } else { client.chatMessage(steamID, "You wrote an unknown command. You can type !commands to learn commands."); } console.log("Message Sender steamID: " + steamID.getSteam3RenderedID() + ": " + message); }); this is the sample code I can only use the first command, I want everyone to use the other commands, but other commands don't work so !help doesn't work I hope you understand thanks in advance <3 Quote
Perport Posted May 13, 2020 Report Posted May 13, 2020 client.on("friendMessage", function (steamID, message) { if(message == "!test" || message == "!put these commands like this here you want only groupmembers to use" || message == "!anothercmd"){ getGroup("mygroupname",members => { if (members.length > 0) { if (message == "!test") { if (members.includes(steamID.accountid)) { client.chatMessage(steamID, "Test Message"); } else client.chatMessage(steamID, "You have to join our steam group"); } else if(message == "!membercmd2"){ // } } else { client.chatMessage(steamID, "bot is still loading message"); } }); } else if(message == "!help"){ } else if (message == "!idk"){ } else{ console.log("Unknown command type \"!help\" to see available commands") } }); This should I might have made some mistakes here and there I'm currently on mobile so I can't test it so try it and let me know. And Please indent this code or something it's starting to look weird. Emily 1 Quote
Emily Posted May 14, 2020 Author Report Posted May 14, 2020 Thank you I checked the coding again and corrected my shortcomings now everyone can use other commands I have a question When the person leaves the group, he can still use that command, and someone who joins the group waits for a few minutes to use that command. Can we set this wait time? so I don't want him to use the command instantly when he leaves the group and the person joining the group should not wait, use that command directly Quote
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.