Skip to content

Conversation

Antoine489
Copy link
Contributor

@Antoine489 Antoine489 commented Aug 11, 2025

Versioning information

  • This includes major changes (breaking changes)
  • This includes minor changes (minimal usage changes, minor new features)
  • This includes patches (bug fixes)
  • This does not change functionality at all (code refactoring, comments)

Is this related to an issue?

No

Changes made

I have added a handling or role input for /add commands

Confirmations

  • I have updated related documentation (if necessary)
  • My changes use consistent code style
  • My changes have been tested and confirmed to work

Summary by CodeRabbit

  • New Features
    • Add command now accepts an optional role in addition to an optional member; either or both can be provided to grant ticket access.
    • Sends separate confirmation messages for each added member/role; final success lists all added entities.
  • Bug Fixes
    • Shows an error if neither member nor role is provided.
  • Documentation
    • Updated English translations for new option, messages, and placeholders.

Copy link

coderabbitai bot commented Aug 11, 2025

Walkthrough

The add slash command now accepts optional member and role options (at least one required). It grants channel permissions per provided entity and posts per-entity "added" embeds; final success uses a combined {args} field. English locale entries for the role option and a missing-arguments error were added.

Changes

Cohort / File(s) Summary
Add command logic
src/commands/slash/add.js
Made member optional and added optional role option. Enforced "at least one of member or role" validation. Apply permissions per provided entity and send per-entity "added" embeds; final success message uses combined {args}. JSDoc import-path single-quote tweaks. Separate log entries for added member/role.
Localization updates
src/i18n/en-GB.yml
Added commands.slash.add.options.role name/description and commands.slash.add.no_args title/description. Updated success message to use {args} instead of {member}. Replaced log.ticket.added with log.ticket.addedMember and log.ticket.addedRole.

Sequence Diagram(s)

sequenceDiagram
  participant User
  participant Bot
  participant DiscordAPI as Discord API

  User->>Bot: /add [member?] [role?]
  Bot->>Bot: Validate at least one of member or role
  alt Neither provided
    Bot-->>User: Error embed (no_args)
  else Member and/or Role provided
    opt Member provided
      Bot->>DiscordAPI: Grant channel perms to Member
      DiscordAPI-->>Bot: Ack
      Bot-->>User: Embed: member added
    end
    opt Role provided
      Bot->>DiscordAPI: Grant channel perms to Role
      DiscordAPI-->>Bot: Ack
      Bot-->>User: Embed: role added
    end
    Bot-->>User: Success message with {args}
  end
Loading

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

Poem

I twitch my whiskers, add a role or friend,
A hop, a nudge—permissions I lend.
If none arrive, I give a tap,
Then cheer as members join the map.
Hooray! The ticket blooms—🥕

Tip

🔌 Remote MCP (Model Context Protocol) integration is now available!

Pro plan users can now connect to remote MCP servers from the Integrations page. Connect with popular remote MCPs such as Notion and Linear to add more context to your reviews and chats.

✨ Finishing Touches
  • 📝 Generate Docstrings
🧪 Generate unit tests
  • Create PR with unit tests
  • Post copyable unit tests in a comment

🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.

Support

Need help? Create a ticket on our support page for assistance with any issues or questions.

CodeRabbit Commands (Invoked using PR/Issue comments)

Type @coderabbitai help to get the list of available commands.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Status, Documentation and Community

  • Visit our Status Page to check the current availability of CodeRabbit.
  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 2

🔭 Outside diff range comments (1)
src/commands/slash/add.js (1)

184-195: Update logging to include both member and role.

The logging only captures the member being added but ignores the role. Both should be logged when provided.

 logTicketEvent(this.client, {
 	action: 'update',
 	diff: {
 		original: {},
-		updated: { [getMessage('log.ticket.added')]: member.user.tag },
+		updated: { 
+			[getMessage('log.ticket.added')]: [
+				member?.user.tag, 
+				role?.name
+			].filter(Boolean).join(', ')
+		},
 	},
 	target: {
 		id: ticket.id,
 		name: `<#${ticket.id}>`,
 	},
 	userId: interaction.user.id,
 });
🧹 Nitpick comments (2)
src/commands/slash/add.js (2)

44-48: Fix inconsistent import path styles.

The JSDoc annotations use inconsistent quote styles for import paths. Line 44 uses single quotes while line 47 uses single quotes without the .js extension.

 /**
- * @param {import('discord.js').ChatInputCommandInteraction} interaction
+ * @param {import('discord.js').ChatInputCommandInteraction} interaction
  */
 async run(interaction) {
-	/** @type {import('client')} */
+	/** @type {import('../../client')} */
 	const client = this.client;

112-138: Extract permission configuration to reduce duplication.

The permission overwrites configuration is duplicated between member and role handling. Consider extracting it to a constant or method.

+const TICKET_PERMISSIONS = {
+	AttachFiles: true,
+	EmbedLinks: true,
+	ReadMessageHistory: true,
+	SendMessages: true,
+	ViewChannel: true,
+};
+
 if (member) {
 
 	await ticketChannel.permissionOverwrites.edit(
 		member,
-		{
-			AttachFiles: true,
-			EmbedLinks: true,
-			ReadMessageHistory: true,
-			SendMessages: true,
-			ViewChannel: true,
-		},
+		TICKET_PERMISSIONS,
 		`${interaction.user.tag} added ${member.user.tag} to the ticket`,
 	);

Apply the same change to the role section (lines 142-152):

 	await ticketChannel.permissionOverwrites.edit(
 		role,
-		{
-			AttachFiles: true,
-			EmbedLinks: true,
-			ReadMessageHistory: true,
-			SendMessages: true,
-			ViewChannel: true,
-		},
+		TICKET_PERMISSIONS,
 		`${interaction.user.tag} added ${role.name} to the ticket`,
 	);
📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between fc502bf and 8e6111a.

📒 Files selected for processing (2)
  • src/commands/slash/add.js (5 hunks)
  • src/i18n/en-GB.yml (1 hunks)
🧰 Additional context used
🧬 Code Graph Analysis (1)
src/commands/slash/add.js (6)
src/commands/slash/tickets.js (2)
  • member (43-43)
  • ExtendedEmbedBuilder (4-4)
src/commands/user/create.js (1)
  • ExtendedEmbedBuilder (3-3)
src/commands/slash/help.js (1)
  • ExtendedEmbedBuilder (3-3)
src/commands/slash/move.js (1)
  • ExtendedEmbedBuilder (3-3)
src/commands/slash/tag.js (1)
  • ExtendedEmbedBuilder (3-3)
src/commands/message/pin.js (1)
  • ExtendedEmbedBuilder (2-2)
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (1)
  • GitHub Check: Codacy Static Code Analysis
🔇 Additional comments (4)
src/i18n/en-GB.yml (3)

54-56: LGTM! Clear error messaging for missing arguments.

The new error message clearly communicates that at least one argument (member or role) is required when using the add command.


61-63: LGTM! Consistent role option definition.

The role option follows the same structure as the existing member option, maintaining consistency in the localization file.


68-68: Verify placeholder consistency across all locales

We’ve updated the add-success message in en-GB (src/i18n/en-GB.yml:68) to use {args} instead of {member}. Please confirm that:

  • All other locale files are updated to use {args} (not {member}) for this message.
  • The command’s formatting logic correctly handles cases where both member and role are provided.

Pinpoint locations for review:

  • src/i18n/en-GB.yml (line 68):
    description: "{args} has been added to {ticket}."
  • Search src/i18n/*.yml for occurrences of {member} and update to {args} as needed.
src/commands/slash/add.js (1)

19-27: LGTM! Well-structured option configuration.

The options are properly configured with both member and role set as optional (required: false), allowing flexible usage of the command.

Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 0

♻️ Duplicate comments (1)
src/commands/slash/add.js (1)

95-99: Fix incorrect required flag for getMember; makes the new “at least one of member/role” logic unreachable.

getMember('member', true) will force the option to be present and throw before your custom no-args check. Since both options are optional, this must be false.

Apply:

-const member = interaction.options.getMember('member', true);
+const member = interaction.options.getMember('member', false);
🧹 Nitpick comments (4)
src/commands/slash/add.js (4)

49-50: Verify the JSDoc type import path for client.

The import('client') path may not resolve unless you have a declared module named "client" in your type roots. If your custom client is exported from a local module (e.g., src/client.js/ts), consider pointing to it explicitly.

If needed:

-/** @type {import('client')} */
+/** @type {import('../../client').Client} */

Adjust the relative path and exported type name to match your codebase. If you do have a global "client" module declaration, feel free to ignore this.


114-166: Reduce duplication and centralize permission overwrite payload.

The overwrite payload is duplicated for member and role. Centralizing it reduces maintenance risk and keeps the two paths in lockstep. Also, consider batching operations when both inputs are present.

Here’s a minimal refactor within this scope:

+const overwriteAllow = {
+  AttachFiles: true,
+  EmbedLinks: true,
+  ReadMessageHistory: true,
+  SendMessages: true,
+  ViewChannel: true,
+};
+
 if (member) {
-  await ticketChannel.permissionOverwrites.edit(
-    member,
-    {
-      AttachFiles: true,
-      EmbedLinks: true,
-      ReadMessageHistory: true,
-      SendMessages: true,
-      ViewChannel: true,
-    },
-    `${interaction.user.tag} added ${member.user.tag} to the ticket`,
-  );
+  await ticketChannel.permissionOverwrites.edit(
+    member,
+    overwriteAllow,
+    `${interaction.user.tag} added ${member.user.tag} to the ticket`,
+  );
   // ...
 }
 
 if (role) {
-  await ticketChannel.permissionOverwrites.edit(
-    role,
-    {
-      AttachFiles: true,
-      EmbedLinks: true,
-      ReadMessageHistory: true,
-      SendMessages: true,
-      ViewChannel: true,
-    },
-    `${interaction.user.tag} added ${role.name} to the ticket`,
-  );
+  await ticketChannel.permissionOverwrites.edit(
+    role,
+    overwriteAllow,
+    `${interaction.user.tag} added ${role.name} to the ticket`,
+  );
   // ...
 }

Optionally, when both are present, you can run the edit/send pairs sequentially (as now) or selectively parallelize with care. Err surfaces are friendlier when kept sequential, so parallelization is optional here.


180-182: Nit: prefer a word-joiner over ' & ' for args, or let i18n own the joiner.

Using a symbol is language-agnostic but less natural. Given you localize everything else, consider using " and " (as previously suggested) or let i18n provide a joiner for locale-correct list formatting.

-args: [member?.toString(), role?.toString()].filter(Boolean).join(' & '),
+args: [member?.toString(), role?.toString()].filter(Boolean).join(' and '),

If you want full localization, expose the joiner or list formatter from i18n and build the args via that API.


186-199: Check logging schema: localized keys in diff.updated may hamper downstream analytics.

You’re using [getMessage('log.ticket.addedMember')] / [...addedRole] as dynamic object keys. If consumers expect stable machine-readable keys, using localized text as keys can fragment metrics per locale.

If your log pipeline expects stable keys, consider:

- updated: { [getMessage('log.ticket.addedMember')]: member.user.tag },
+ updated: { addedMember: member.user.tag },

and apply localization at the presentation layer instead of the event payload.

Also applies to: 201-214

📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

💡 Knowledge Base configuration:

  • MCP integration is disabled by default for public repositories
  • Jira integration is disabled by default for public repositories
  • Linear integration is disabled by default for public repositories

You can enable these sources in your CodeRabbit configuration.

📥 Commits

Reviewing files that changed from the base of the PR and between f759527 and 58aae34.

📒 Files selected for processing (2)
  • src/commands/slash/add.js (4 hunks)
  • src/i18n/en-GB.yml (2 hunks)
🚧 Files skipped from review as they are similar to previous changes (1)
  • src/i18n/en-GB.yml
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (2)
  • GitHub Check: Analyze (javascript)
  • GitHub Check: Codacy Static Code Analysis
🔇 Additional comments (4)
src/commands/slash/add.js (4)

21-29: Role option addition looks correct and consistent with i18n plumbing.

  • member option is now optional, matching runtime logic.
  • role option is properly added as optional Role type.
  • The mapping below populates name/description via i18n, so omission of inline description fields here is fine.

46-46: JSDoc for interaction type is accurate.

Using import('discord.js').ChatInputCommandInteraction is the right annotation for v14.


100-112: Good: explicit “no arguments” branch with localized feedback.

Once getMember is optional (see above), this block correctly handles the case where neither member nor role is supplied.


95-96: Channel type assumptions: ensure tickets are always text channels.

ticketChannel is annotated as TextChannel, and you’re using permissionOverwrites.edit, which is not supported on all channel types (e.g., threads behave differently). If tickets can be threads or other channel types, the cast and overwrite ops may fail.

Would you like me to scan the repo to confirm ticket channel creation always produces a TextChannel and not a Thread? If it’s strictly TextChannel, the current approach is fine; otherwise we should widen the type and gate overwrite logic accordingly.

Also applies to: 114-124, 142-152

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant