Advertisement
Frostyy22

index.js

Apr 12th, 2023
783
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. const { Client, IntentsBitField, ActivityType} = require('discord.js');
  2. const fs = require('fs');
  3. const cron = require('node-cron');
  4. const fact = require('./commands/fact');
  5. const wikipedia = require('../commands/wikipedia');
  6. const search = require('../commands/googleSearch');
  7. const imageSearch = require('../commands/googleImageSearch')
  8. const quiz = require('../commands/quiz')
  9.  
  10. const client = new Client({
  11.     intents: [
  12.         IntentsBitField.Flags.Guilds,
  13.         IntentsBitField.Flags.GuildMembers,
  14.         IntentsBitField.Flags.GuildMessages,
  15.         IntentsBitField.Flags.MessageContent,
  16.         IntentsBitField.Flags.GuildPresences,      
  17.     ],
  18. });
  19.  
  20. client.on('ready', () => {
  21.     console.log(`Logged in as ${client.user.tag}!`);
  22.  
  23.     client.user.setActivity("the battlefield", { type: ActivityType.Watching })
  24.     client.user.setStatus("dnd")
  25. });
  26.  
  27.  
  28. // Get the command
  29. client.on('interactionCreate', async (interaction) => {
  30.     if (!interaction.isChatInputCommand()) return;
  31.  
  32.   // Fact
  33.   if (interaction.commandName === 'fact') {
  34.     fact(interaction);
  35.   }
  36.  
  37.   // Wikipedia
  38.   if (interaction.commandName === 'fact') {
  39.     wikipedia(interaction);
  40.   }
  41.  
  42.   // Google search
  43.   if (interaction.commandName === 'search') {
  44.     search(interaction);
  45.   }
  46.  
  47.   // Google image search
  48.   if (interaction.commandName === 'image-search') {
  49.     imageSearch(interaction);
  50.   }
  51.  
  52.   //Quiz
  53.   if (interaction.commandName === 'ww2-quiz') {
  54.     quiz(interaction);
  55.   }
  56. })
  57.  
  58. cron.schedule('57 19 * * *', () => {
  59.   try {
  60.     const facts = JSON.parse(fs.readFileSync('facts.json', 'utf8'));
  61.     console.log(facts);
  62.  
  63.     const randomFact = facts[Math.floor(Math.random() * facts.length)];
  64.  
  65.     const channel = client.channels.cache.get('1094015791713759372');
  66.     channel.send(randomFact);
  67.   } catch (error) {
  68.     console.error(`${error}`);
  69.   }
  70. });
  71.  
  72. client.login("");
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement