Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

168
Visualizações
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 Respostas
Responde à pergunta

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 Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda