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.

65 lines
1.6 KiB

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