Advertisement
Lorky

DJSV14 auto-role [Optimized Interaction]

Apr 1st, 2023
1,067
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
JavaScript 1.51 KB | Source Code | 0 0
  1. const roles = {
  2.   age: {
  3.     ra1: '1062793936357302372',
  4.     ra2: '1062801143400497193',
  5.     ra3: '1062801213332148395',
  6.     ra4: '1062801279153361076',
  7.   },
  8.   pronouns: {
  9.     rp1: '1062801444404723752',
  10.     rp2: '1062801523572220025',
  11.     rp3: '1062801557260861491',
  12.     rp4: '1062801608196501504',
  13.     rp5: '1062801875612737586',
  14.   },
  15.   notif: {
  16.     rn1: '1062802495488929933',
  17.     rn2: '1062802571758141600',
  18.     rn3: '1062802787097911316',
  19.     rn4: '1062803011501568041',
  20.     rn5: '1062803204733141084',
  21.   },
  22. };
  23.  
  24. const SELFROLEspacer = '1062800788851798036';
  25.  
  26. module.exports = {
  27.   name: 'interactionCreate',
  28.   /**
  29.    * @param {SelectMenuInteraction} interaction
  30.    * @param {Client} client
  31.    */
  32.   async execute(interaction, client) {
  33.     if (!interaction.isStringSelectMenu()) return;
  34.  
  35.     const selected = interaction.values;
  36.     const member = interaction.member;
  37.     const selectionid = interaction.customId;
  38.  
  39.     if (!roles[selectionid]) return;
  40.  
  41.     Object.keys(roles[selectionid]).forEach((key) => {
  42.       const roleId = roles[selectionid][key];
  43.       if (selected.includes(key)) {
  44.         member.roles.add(roleId);
  45.       } else {
  46.         member.roles.remove(roleId);
  47.       }
  48.     });
  49.  
  50.     if (!member.roles.cache.has(SELFROLEspacer)) {
  51.       member.roles.add(SELFROLEspacer);
  52.     }
  53.  
  54.     interaction.reply({
  55.       content: 'Vos rôles ont été mis à jour',
  56.       ephemeral: true,
  57.     });
  58.  
  59.     setTimeout(function () {
  60.       interaction.deleteReply();
  61.     }, 2000);
  62.   },
  63. };
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement