Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

167
Views
Player Login/ Logout Feed for Discord

I'm currently working on a Discord Bot for my game server and I would like to implement a Player Login/Logout feed. I have set up a SQL database where it stores information about a player, I have created a Table name called 'users' and in this table I have a column called 'presence' this has a default value called 'offline' and switches to 'online' when a player has joined the server.

My goal here is to have the Bot send a message only when the column 'presence' changes from 'offline' to 'online' and also from 'online' to 'offline'. enter image description here

So far I'm able to get the bot to send a message when the bot starts about a players presence, my question is how to make it 'listen' for when a player presence has changed and then send a message?.

I hope this makes sense and thanks in advance.

main.js

setInterval(() => {
    PlayerFeed.publish(client);
  }, 30000);
});

PlayerFeed.js

const { Users } = require("../dbObjects");
const { Sequelize } = require("sequelize");
const { codeBlock } = require("@discordjs/builders");

module.exports = {
    publish: (client) => {
        const channel = client.guilds.cache.get(Config.guildId).channels.cache.get(Config.PlayerFeedChannel)
        Users.findAll({where: {presence: 'online'}, order: ['presenceUpdatedAt']}).then(users => {
            users.forEach(Users => {
                
             let presence = Users.presence;
                if(presence == 'online')
                channel.send(codeBlock("diff",
                `+Login ID:${Users.steamId64} ID:${Users.ign}`));
                
                else if 
                (presence == 'offline')
                channel.send(codeBlock("diff",
                `-Logout ID:${Users.steamId64} ID:${Users.ign}`));
              })
            })
          }
        }
about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

So, if I understand well, "presence" is set to "online" when user join your guild and it set to "offline" if he leaves it right?

If so, you should use Discord Events to manage this.

on guildMemberAdd => add user to db with presence online => send message in your feed

on guildMemberRemove => set presence to offline => send message in your feed

about 4 years ago · Juan Pablo Isaza Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!