Bot discord pour le serveur d'Ingénieurs pour Demain
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.

index.js 3.6KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102
  1. /*
  2. Bot Ingénieurs pour demain
  3. Developped by Valentin SERVIERES, if you have any question, you can contact me by Discord MagicTINTIN#4389
  4. - Discord.js version v12 (depreciated)
  5. */
  6. console.log("Starting...");
  7. const { appID, publicKey, token, prefix } = require('./config/credentials.json');
  8. const fs = require('fs');
  9. const path = require('path');
  10. const Discord = require('discord.js');
  11. const { Client, Intents, MessageEmbed } = require('discord.js');
  12. // Only mandatory for Discord.js v13
  13. const client = new Client({
  14. intents: [Intents.FLAGS.GUILDS, Intents.FLAGS.GUILD_MEMBERS, Intents.FLAGS.GUILD_BANS, Intents.FLAGS.GUILD_EMOJIS_AND_STICKERS, Intents.FLAGS.GUILD_INTEGRATIONS, Intents.FLAGS.GUILD_WEBHOOKS, Intents.FLAGS.GUILD_INVITES, Intents.FLAGS.GUILD_VOICE_STATES, Intents.FLAGS.GUILD_PRESENCES, Intents.FLAGS.GUILD_MESSAGES, Intents.FLAGS.GUILD_MESSAGE_REACTIONS, Intents.FLAGS.GUILD_MESSAGE_TYPING, Intents.FLAGS.DIRECT_MESSAGES, Intents.FLAGS.DIRECT_MESSAGE_REACTIONS, Intents.FLAGS.DIRECT_MESSAGE_TYPING],
  15. });
  16. exports.client = client;
  17. // --- INITIALIZING BOT ---
  18. config = JSON.parse(fs.readFileSync(path.resolve(`./config/botinfo.json`)));
  19. console.log("config found\ngetting log channel id");
  20. const logch = config.logChannelID
  21. exports.logch = logch;
  22. // Import functions
  23. const random = require("./functions/random.js");
  24. const logger = require("./functions/logger.js");
  25. const msgcheck = require("./functions/messageCheck.js");
  26. const rolereact = require("./functions/rolereaction.js");
  27. // Import commands
  28. client.commands = new Discord.Collection();
  29. const commandFiles = fs.readdirSync('./commands').filter(file => file.endsWith('.js'));
  30. for (const file of commandFiles) {
  31. const command = require(`./commands/${file}`);
  32. client.commands.set(command.name, command);
  33. }
  34. client.once('ready', () => {
  35. // cache message that could be used for reactions
  36. rolereact.cache();
  37. console.log('Ready to act !')
  38. client.user.setActivity(config.activity, { type: 'PLAYING' });
  39. client.channels.cache.get(logch).send("**❕ BOT ONLINE** - ready to act");
  40. });
  41. // --- END INITIALIZATION ---
  42. client.on('message', async message => {
  43. if (message.author.bot) return
  44. if (!message.channel.guild) {
  45. return logger.all(message.author.tag + " a envoyé un mp : " + message.content)
  46. }
  47. // For more details see /functions/messageCheck.js
  48. msgcheck.general(message);
  49. // Command trigger
  50. if (!message.content.startsWith(prefix) || message.author.bot) return;
  51. const args = message.content.slice(prefix.length).split(/ +/);
  52. const command = args.shift().toLocaleLowerCase();
  53. if (!client.commands.has(command)) return;
  54. try {
  55. client.commands.get(command).execute(message, args);
  56. logger.all(`🔨 ${message.author.tag} - \`${message}\``)
  57. } catch (error) {
  58. console.error(error);
  59. }
  60. });
  61. client.on('guildMemberAdd', async member => {
  62. try {
  63. logger.all(`🆕 ${member.user.tag} vient d'arriver sur le serveur`);
  64. // update user file
  65. msgcheck.memberUpdate(member, "join");
  66. } catch (err) { console.error(err); }
  67. });
  68. client.on('guildMemberRemove', async member => {
  69. try {
  70. logger.all(`❌ ${member.user.tag} vient de quitter le serveur`);
  71. // update user file
  72. msgcheck.memberUpdate(member, "left");
  73. } catch (error) {
  74. }
  75. });
  76. client.on('messageReactionAdd', (reaction, user) => {
  77. rolereact.give(reaction, user);
  78. });
  79. client.on('messageReactionRemove', (reaction, user) => {
  80. rolereact.remove(reaction, user);
  81. });
  82. client.login(token);