0

I would like to know if there is a way to get the guild id with the userUpdate event i need this for mongodb LogsSchema.findOne({ guildId: the id of the guild})

client.on('userUpdate', (oldUser, newUser) => {

   const LogsSchema = require('./structures/LogsChannel')

   LogsSchema.findOne({ guildId: message.guild.id}, async (err, logsdata) => {
        if (!logsdata) return;

    const channel = logsdata.logschannelId

    if (oldUser.discriminator !== newUser.discriminator) client.channels.cache.get(channel).send({ embeds: [
        client.functions.embed()
        .setTitle(`> 【 PROFIL 】`)     
        .setThumbnail(newUser.displayAvatarURL())
        .setDescription(` <@${newUser.id}> a changé son tag !`)
        .addFields(
            { name: 'Ancien tag:', value: `\`#${oldUser.discriminator}\``, inline: true}, 
            { name: 'Nouveau tag:', value: `\`#${newUser.discriminator}\``, inline: true}, 
        )
        .setTimestamp()
        .setFooter(`ID ${newUser.id}`)
    ]})
  })
Dinamo
  • 9
  • 3
  • `User`s aren't connected to a `Guild` – MrMythical Oct 14 '21 at 14:56
  • See [this question](https://stackoverflow.com/questions/63979076/what-is-the-difference-between-a-user-and-a-guildmember-in-discord-js) – MrMythical Oct 14 '21 at 14:56
  • Yes but i still dont know how to get the guild id, so its not possible ? in no way ? i tried with guildMemberUpdate but that dont work, i really need the guild id from this member, when he change avatar or username – Dinamo Oct 15 '21 at 01:39
  • You would have to hard-code the guild id. Otherwise I don’t know where you expect to get the guild id from – MrMythical Oct 15 '21 at 01:41
  • A possible solution - loop through the servers your bot is in and for each server find if the user is a member of that server. If he is, you can use that guild id. Kinda resource expensive, but the closest solution I could think of. – D J Oct 15 '21 at 10:12

0 Answers0