Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: Add ApplicationEmoji to EmojiResolvable and MessageReaction#emoji #10477

Open
wants to merge 8 commits into
base: main
Choose a base branch
from

Conversation

Moebits
Copy link
Contributor

@Moebits Moebits commented Sep 3, 2024

Please describe the changes this PR makes and why it should be merged:

When using typescript you can't react to a message with an ApplicationEmoji because EmojiResolvable lacks the type.

Edit: I also updated BaseGuildEmojiManager.js and added ApplicationEmoji to the MessageReaction#emoji getter.

Status and versioning classification:

  • Code changes have been tested against the Discord API, or there are no code changes
  • I know how to update typings and have done so, or typings don't need updating

@Moebits Moebits requested a review from a team as a code owner September 3, 2024 05:22
Copy link

vercel bot commented Sep 3, 2024

The latest updates on your projects. Learn more about Vercel for Git ↗︎

2 Skipped Deployments
Name Status Preview Comments Updated (UTC)
discord-js ⬜️ Ignored (Inspect) Visit Preview Sep 12, 2024 4:13pm
discord-js-guide ⬜️ Ignored (Inspect) Visit Preview Sep 12, 2024 4:13pm

@Moebits Moebits changed the title types: Add ApplicationEmoji to EmojiResolvable and MessageReaction#emoji types: Add ApplicationEmoji to EmojiResolvable Sep 3, 2024
@imnaiyar
Copy link
Contributor

imnaiyar commented Sep 3, 2024

This may also need updating

/**
* Data that can be resolved into a GuildEmoji object. This can be:
* * A Snowflake
* * A GuildEmoji object
* * A ReactionEmoji object
* @typedef {Snowflake|GuildEmoji|ReactionEmoji} EmojiResolvable

@Moebits
Copy link
Contributor Author

Moebits commented Sep 3, 2024

Thanks I updated BaseGuildEmojiManager.js and it seemed to fix the equality comparison with MessageReaction#emoji as well.


public burstColors: string[] | null;
public readonly client: Client<true>;
public count: number;
public countDetails: ReactionCountDetailsData;
public get emoji(): GuildEmoji | ReactionEmoji;
public get emoji(): GuildEmoji | ReactionEmoji | ApplicationEmoji;
Copy link
Contributor

Choose a reason for hiding this comment

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

In its current state, it is not possible for MessageReaction#emoji along with its associated private property to return an ApplicationEmoji, which would make these typings inaccurate.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I think it makes sense for a MessageReaction done by the bot with an ApplicationEmoji to return ApplicationEmoji for its emoji property. Do you know where I can make these changes?

Copy link
Member

Choose a reason for hiding this comment

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

Since application emojis need to be fetched to be had, I wouldn't actually try to squeeze that in. it's fine to leave it as before

Copy link
Contributor

@Qjuh Qjuh Sep 4, 2024

Choose a reason for hiding this comment

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

why not add a cache check for ApplicationEmoji here?

if (this._emoji.id) {
const emojis = this.message.client.emojis.cache;
if (emojis.has(this._emoji.id)) {
const emoji = emojis.get(this._emoji.id);
this._emoji = emoji;
return emoji;
}
}

If it‘s not in cache the behavior would stay as is, if cached you‘d get the ApplicationEmoji.

Copy link
Member

Choose a reason for hiding this comment

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

Oof, that getter. I'd maybe add that logic into the getter to store app emojis if we really wanna go there

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I have added ApplicationEmoji lookup to the getter.

Copy link
Contributor

Choose a reason for hiding this comment

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

That now changes the scope of the PR to not be types only. Please edit the PR title and description accordingly and make sure you actually tested that change.

@Moebits Moebits changed the title types: Add ApplicationEmoji to EmojiResolvable feat: Add ApplicationEmoji to EmojiResolvable and MessageReaction#emoji Sep 4, 2024
// Check to see if the emoji has become known to the client
if (this._emoji.id) {
const emojis = this.message.client.emojis.cache;
if (emojis.has(this._emoji.id)) {
const emoji = emojis.get(this._emoji.id);
this._emoji = emoji;
return emoji;
} else {
const applicationEmojis = this.message.client.application.emojis.cache;
Copy link
Member

Choose a reason for hiding this comment

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

Should be moved under line 124

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
Status: Review in Progress
Development

Successfully merging this pull request may close these issues.

5 participants