I’ve dealt with similar issues when setting up FiveM status bots. The error you’re seeing usually pops up when the bot can’t find the guild or channel you’re trying to access. Double-check that your guild and channel IDs are correct in the settings file. Also, make sure your bot has actually joined the server and has the right permissions.
One thing I’ve found helpful is to add some logging to see what’s happening. Try adding console.log statements before accessing the guild and channel, like this:
This will help you see if the bot is in the right place. If these logs show everything’s fine, the issue might be with the gameserver-query package. I’ve had better luck using the fivem-api package for querying FiveM servers. It’s more reliable and easier to use in my experience.
Looking at your code, I don’t see any reference to ‘memberCount’, which is odd given the error you’re encountering. This suggests the issue might be in a part of the code you haven’t shared. However, I can spot a potential problem in your updateStatus function.
You’re assuming the guild and channel IDs are valid and accessible. If either of these isn’t found, you’ll get an ‘undefined’ error when trying to access properties. To fix this, add some error checking:
function updateStatus() {
serverQuery.query(settings.serverAddress, settings.serverPort, (error, data) => {
if (error) {
console.error('Query failed:', error);
} else {
const guild = bot.guilds.cache.get('123456789012345678');
if (!guild) {
console.error('Guild not found');
return;
}
const statusChannel = guild.channels.cache.get('987654321098765432');
if (!statusChannel) {
console.error('Status channel not found');
return;
}
statusChannel.setName(`Players: ${data.players}/${data.maxPlayers}`);
}
setTimeout(updateStatus, 10000);
});
}
This should help pinpoint where the issue is occurring. Also, ensure your bot has the necessary permissions to change channel names.