Skip to content
This repository has been archived by the owner on Sep 29, 2022. It is now read-only.

🐛 Fix getting user #91

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 4 additions & 5 deletions src/commands/Suggestions/suggestions.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,11 +26,10 @@ module.exports = class MySuggestionsCommand extends Command {
await message.delete().catch(O_o => {});

const getSubmitter = userID => {
const re = new RegExp(MessageMentions.USERS_PATTERN, 'g');
const isMention = re.test(userID);

const id = isMention ? re.exec(userID)[1] : userID;

let id;
const mention = userID.matchAll(MessageMentions.USERS_PATTERN).next().value;
if (!mention) id = userID;
else id = mention[1];
Comment on lines +29 to +32
Copy link
Member

@acollierr17 acollierr17 Apr 3, 2022

Choose a reason for hiding this comment

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

The code looks solid for starters. However, I think we can refactor this logic even more with the following:

const mention = userID.matchAll(MessageMentions.USERS_PATTERN).next().value;
const id = (mention && mention[1]) ?? userID;

Let me know what you think!

return message.guild
? message.guild.members.fetch({ user: id, cache: false })
: this.client.users.fetch(id, false);
Expand Down