Advertisement
Nimbi

Pylon Role Command

Jul 28th, 2022 (edited)
1,407
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. const Commands = discord.interactions.commands;
  2.  
  3. Commands.register(
  4.   {
  5.     name: 'role',
  6.     description: 'Pylon role system.',
  7.     ackBehavior: Commands.AckBehavior.AUTO_EPHEMERAL,
  8.     options: (opts) => ({
  9.       member: opts.guildMember({
  10.         name: 'member',
  11.         description: 'Specify a member.',
  12.         required: true,
  13.       }),
  14.       choice: opts.string({
  15.         name: 'choice',
  16.         description: 'select an option',
  17.         choices: ['+', '-'],
  18.         required: true,
  19.       }),
  20.       role: opts.guildRole({
  21.         name: 'role',
  22.         description: 'select a role to add or remove',
  23.         required: true,
  24.       }),
  25.     }),
  26.   },
  27.   async (interaction, { member, choice, role }) => {
  28.     let self = await discord.getBotUser();
  29.  
  30.     try {
  31.       if (choice == '+') {
  32.         if (!interaction.member.can(discord.Permissions.MANAGE_ROLES))
  33.           return await interaction.respondEphemeral(
  34.             '⛔ `Permissions Error` You need the permission **Manage Roles** to use this command.'
  35.           );
  36.  
  37.         await member.addRole(role.id).catch((_) => {
  38.           interaction.respondEphemeral('```ts\n' + _ + '\n```');
  39.           console.log(`>> | ${_}`);
  40.         });
  41.         await interaction.respond(
  42.           `Successfully applied the role: **${role.name}** to member: **${member.user.username}**`
  43.         );
  44.       } else if (choice == '-') {
  45.         if (!interaction.member.can(discord.Permissions.MANAGE_ROLES))
  46.           return await interaction.respondEphemeral(
  47.             '⛔ `Permissions Error` You need the permission **Manage Roles** to use this command.'
  48.           );
  49.  
  50.         await member.removeRole(role.id).catch((_) => {
  51.           interaction.respondEphemeral('```ts\n' + _ + '\n```');
  52.           console.log(`>> | ${_}`);
  53.         });
  54.         await interaction.respond(
  55.           `Successfully removed the role: **${role.name}** from member: **${member.user.username}**`
  56.         );
  57.       }
  58.     } catch (_) {
  59.       // @ts-ignore
  60.       console.log(_.stack);
  61.       let channel = await discord.getTextChannel('channel id');
  62.       let e = new discord.Embed();
  63.       e.setTitle('Error Triggered');
  64.       e.setDescription('```ts\n' + _ + '\n```');
  65.       e.setFields([
  66.         {
  67.           name: 'Error Stack',
  68.           // @ts-ignore
  69.           value: ['```ts', _.stack, '```'].join('\n'),
  70.           inline: false,
  71.         },
  72.       ]);
  73.       e.setColor(discord.decor.RoleColors.DARK_RED);
  74.       e.setTimestamp(new Date().toISOString());
  75.       e.setFooter({
  76.         text: `Powered by ${self.username}`,
  77.         iconUrl: self.getAvatarUrl(),
  78.       });
  79.       await interaction.respondEphemeral('```ts\n' + _ + '\n```');
  80.       await channel?.sendMessage({ embed: e }).catch((_) => {
  81.         console.log(`>> | ${_}`);
  82.       });
  83.     }
  84.   }
  85. );
  86.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement