Simp-O-Matic

Dumb Discord bot in TS.
git clone git://git.knutsen.co/Simp-O-Matic
Log | Files | Refs | README | LICENSE

bot.js (1731B)


require('dotenv').config();
const Discord = require('discord.js');
const DiscordClient = new Discord.Client();
const CommandSystem = require('./command-system.js')();

CommandSystem.load(() => {
  console.log('Command system loaded.');
});

DiscordClient.on('ready', () => {
  console.log('DoseBot is online - beep boop');

  // Update game message on launch
  DiscordClient.user
    .setActivity(`my part in reducing harm!`, { type: 'PLAYING' })
    .then(presence => console.log(`Activity set: ${JSON.stringify(presence.game)}`))
    .catch(console.error);

  // Print guild list
  let guilds = DiscordClient.guilds.cache;
  const userCount = guilds
    .map(guild => guild.memberCount)
    .reduce((x, y) => x + y, 0);

  console.log(`Currently serving ${userCount} users on ${guilds.length} guilds`);
  for (let guildComponents of guilds) {
    let guildId = guildComponents[0];
    let guild = guildComponents[1];
    console.log(`- ${guildId} - ${guild.name} (${guild.memberCount} members)`);

    if (guildId == "697833083201650689") {
      console.log("leaving guild");
      guild.leave().then(g => console.log("Left the guild")).catch(console.error);
    }
  }
});

DiscordClient.on('guildCreate', guild => {
  console.log(`New server joined - Name: ${guild.name} Members: ${guild.memberCount}`);
});

DiscordClient.on('message', message => {
  const guild = message.guild || {};
  const channel = message.channel.name;
  const author = `${message.author.id} ${message.author.username}#${message.author.discriminator}`;

  console.log(`[${guild.id} ${guild.name} #${channel}] <${author}> -- ${message.content}`);

  CommandSystem.execute(DiscordClient, message);
});

DiscordClient.login(process.env.DISCORD_API_TOKEN);