You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

67 lines
1.6 KiB

  1. const fs = require('fs')
  2. const Discord = require('discord.js');
  3. const Client = require('./client');
  4. const fetch = require("node-fetch");
  5. const {
  6. prefix,
  7. token,
  8. } = require('./config.json');
  9. const client = new Client();
  10. client.commands = new Discord.Collection();
  11. const commandFiles = fs.readdirSync('./commands').filter(file => file.endsWith('.js'));
  12. for (const file of commandFiles) {
  13. const command = require(`./commands/${file}`);
  14. client.commands.set(command.name, command);
  15. }
  16. console.log(client.commands);
  17. client.once('ready', () => {
  18. console.log('Ready!');
  19. });
  20. client.once('reconnecting', () => {
  21. console.log('Reconnecting!');
  22. });
  23. client.once('disconnect', () => {
  24. console.log('Disconnect!');
  25. });
  26. client.on('message', async message => {
  27. if (message.author.bot) return;
  28. if (!message.content.startsWith(prefix)) return;
  29. const args = message.content.slice(prefix.length).split(/ +/);
  30. const commandName = args.shift().toLowerCase();
  31. if (!client.commands.has(commandName)) return;
  32. const command = client.commands.get(commandName);
  33. const permitted_roles = client.commands.get(commandName)["roles"];
  34. has_roles = false
  35. if (permitted_roles){
  36. for(i = 0; i < permitted_roles.length; i++){
  37. if(message.member.roles.cache.has(permitted_roles[i])){
  38. has_roles = true
  39. }
  40. }
  41. if (!has_roles && permitted_roles.length != 0){
  42. message.reply('You are not allowed to run this command!');
  43. return;
  44. }
  45. }
  46. try {
  47. command.execute(message);
  48. } catch (error) {
  49. console.error(error);
  50. message.reply('There was an error trying to execute that command!');
  51. }
  52. });
  53. client.login(token);