Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- const Commands = discord.interactions.commands;
- Commands.register(
- {
- name: 'role',
- description: 'Pylon role system.',
- ackBehavior: Commands.AckBehavior.AUTO_EPHEMERAL,
- options: (opts) => ({
- member: opts.guildMember({
- name: 'member',
- description: 'Specify a member.',
- required: true,
- }),
- choice: opts.string({
- name: 'choice',
- description: 'select an option',
- choices: ['+', '-'],
- required: true,
- }),
- role: opts.guildRole({
- name: 'role',
- description: 'select a role to add or remove',
- required: true,
- }),
- }),
- },
- async (interaction, { member, choice, role }) => {
- let self = await discord.getBotUser();
- try {
- if (choice == '+') {
- if (!interaction.member.can(discord.Permissions.MANAGE_ROLES))
- return await interaction.respondEphemeral(
- '⛔ `Permissions Error` You need the permission **Manage Roles** to use this command.'
- );
- await member.addRole(role.id).catch((_) => {
- interaction.respondEphemeral('```ts\n' + _ + '\n```');
- console.log(`>> | ${_}`);
- });
- await interaction.respond(
- `Successfully applied the role: **${role.name}** to member: **${member.user.username}**`
- );
- } else if (choice == '-') {
- if (!interaction.member.can(discord.Permissions.MANAGE_ROLES))
- return await interaction.respondEphemeral(
- '⛔ `Permissions Error` You need the permission **Manage Roles** to use this command.'
- );
- await member.removeRole(role.id).catch((_) => {
- interaction.respondEphemeral('```ts\n' + _ + '\n```');
- console.log(`>> | ${_}`);
- });
- await interaction.respond(
- `Successfully removed the role: **${role.name}** from member: **${member.user.username}**`
- );
- }
- } catch (_) {
- // @ts-ignore
- console.log(_.stack);
- let channel = await discord.getTextChannel('channel id');
- let e = new discord.Embed();
- e.setTitle('Error Triggered');
- e.setDescription('```ts\n' + _ + '\n```');
- e.setFields([
- {
- name: 'Error Stack',
- // @ts-ignore
- value: ['```ts', _.stack, '```'].join('\n'),
- inline: false,
- },
- ]);
- e.setColor(discord.decor.RoleColors.DARK_RED);
- e.setTimestamp(new Date().toISOString());
- e.setFooter({
- text: `Powered by ${self.username}`,
- iconUrl: self.getAvatarUrl(),
- });
- await interaction.respondEphemeral('```ts\n' + _ + '\n```');
- await channel?.sendMessage({ embed: e }).catch((_) => {
- console.log(`>> | ${_}`);
- });
- }
- }
- );
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement