Skip to Content
All Codes

Guild Stats

 — #Guild Stats

Output :

Guild Stats

Code :

const guild = bot.guilds.cache.get('733807204938940447');
const channel = bot.channels.cache.get('779026126424506379');
const members = guild.members.cache;
const fetched = await channel.messages.fetch({
  limit: 100,
});
const notPinned = fetched.filter(fetchedMsg => !fetchedMsg.pinned);
await channel.bulkDelete(notPinned, true);
const statembed = new Discord.MessageEmbed()
  .setAuthor(
    `${guild.name} Statistics`,
    guild.iconURL({
      dynamic: true,
      size: 2048,
    }),
  )
  .setThumbnail(
    guild.iconURL({
      dynamic: true,
      size: 2048,
    }),
  )
  .setFooter(
    `Total ${guild.memberCount} members and ${
      members.filter(member => member.presence.status !== 'offline').size
    } online members`,
    guild.iconURL({
      dynamic: true,
      size: 2048,
    }),
  )
  .setColor(`RANDOM`).setDescription(`**<a:donline:780989343975604245> Online:** ${
  members.filter(member => member.presence.status === 'online').size
} members
        **<a:didle:780989600482066442> Idle:** ${
          members.filter(member => member.presence.status === 'idle').size
        } members
        **<a:ddnd:780989424901160980> Do Not Disturb:** ${
          members.filter(member => member.presence.status === 'dnd').size
        } members
        **<a:doffline:780989523517636658> Offline:** ${
          members.filter(member => member.presence.status === 'offline').size
        } members`);
bot.channels.cache
  .get(`779026126424506379`)
  .send(statembed)
  .then(async msg => {
    setInterval(function () {
      const updatedstatembed = new Discord.MessageEmbed()
        .setAuthor(
          `${guild.name} Statistics`,
          guild.iconURL({
            dynamic: true,
            size: 2048,
          }),
        )
        .setThumbnail(
          guild.iconURL({
            dynamic: true,
            size: 2048,
          }),
        )
        .setFooter(
          `Total ${guild.memberCount} members and ${
            members.filter(member => member.presence.status !== 'offline').size
          } online members`,
          guild.iconURL({
            dynamic: true,
            size: 2048,
          }),
        )
        .setColor(`RANDOM`).setDescription(`**<a:donline:780989343975604245> Online:** ${
        members.filter(member => member.presence.status === 'online').size
      } members
            **<a:didle:780989600482066442> Idle:** ${
              members.filter(member => member.presence.status === 'idle').size
            } members
            **<a:ddnd:780989424901160980> Do Not Disturb:** ${
              members.filter(member => member.presence.status === 'dnd').size
            } members
            **<a:doffline:780989523517636658> Offline:** ${
              members.filter(member => member.presence.status === 'offline').size
            } members`);
      msg.edit(updatedstatembed);
    }, 30000);
  });

Place the above code in the ready event file or create an event in the main/index.js file.

Join the Discord Server for further assistance.