Advertisement
Danulsan

Untitled

Jun 20th, 2023
32
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.07 KB | None | 0 0
  1. const { Client, GatewayIntentBits, PermissionsBitField, EmbedBuilder, Collection, ActivityType } = require('discord.js');
  2. const { token } = require('./config.json');
  3. const fs = require('fs');
  4. const { setInterval } = require('timers/promises');
  5.  
  6. const prefix = '>';
  7.  
  8. const client = new Client({
  9. intents: [
  10. GatewayIntentBits.Guilds,
  11. GatewayIntentBits.GuildMessages,
  12. GatewayIntentBits.MessageContent,
  13. ],
  14. });
  15.  
  16. client.commands = new Collection();
  17.  
  18.  
  19. // Get the Commands folder for access to individual commands
  20. const commandFiles = fs.readdirSync('./commands').filter(file => file.endsWith('.js'));
  21.  
  22. for (const file of commandFiles) {
  23. const command = require(`./commands/${file}`);
  24. client.commands.set(command.name, command);
  25. }
  26.  
  27.  
  28. //Bot connecting to service and Status
  29. client.on('ready', () => {
  30. console.log('Bot is online!');
  31.  
  32. const activities = [
  33. 'Make sure to vote for your servers! :white_check_mark:',
  34. 'Taking a cat nap :zzz:',
  35. 'Getting zombified! :zombie:',
  36. 'Eating your brains!',
  37. '#support for support'
  38. ];
  39.  
  40. setInterval(() => {
  41. const status = activities[Math.floor(Math.random() * activities.length)];
  42. client.user.setPresence({
  43. activities: [{
  44. name: `${status}`,
  45. type: ActivityType.Custom
  46. }]
  47. });
  48. console.log(status); // Log the current status
  49. }, 5000);
  50. });
  51.  
  52. // Logic for the Commands
  53. client.on('messageCreate', (message) => {
  54. if (!message.content.startsWith(prefix) || message.author.bot) return;
  55.  
  56. const args = message.content.slice(prefix.length).split(/ +/);
  57. const commandName = args.shift().toLowerCase();
  58.  
  59. const command = client.commands.get(commandName);
  60.  
  61. if (!command) return;
  62.  
  63. try {
  64. command.execute(message, args);
  65. } catch (error) {
  66. console.error(error);
  67. message.channel.send('There was an error while executing this command.');
  68. }
  69. });
  70.  
  71. // Login bot with token from config.json
  72. client.login(token);
  73.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement