Skip to content

Commit

Permalink
refactor: add emoji string support for select menu options
Browse files Browse the repository at this point in the history
  • Loading branch information
suneettipirneni committed Mar 7, 2022
1 parent 4f7cab1 commit 28b4c92
Show file tree
Hide file tree
Showing 4 changed files with 34 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -78,8 +78,8 @@ export class UnsafeSelectMenuOption {
}

/**
* Sets the emoji to display on this button
* @param emoji The emoji to display on this button
* Sets the emoji to display on this option
* @param emoji The emoji to display on this option
*/
public setEmoji(emoji: APIMessageComponentEmoji) {
this.data.emoji = emoji;
Expand Down
20 changes: 20 additions & 0 deletions packages/discord.js/src/structures/SelectMenuOption.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
'use strict';

const { SelectMenuOption: BuildersSelectMenuOption } = require('@discordjs/builders');
const Util = require('../util/Util');

class SelectMenuOption extends BuildersSelectMenuOption {
/**
* Sets the emoji to display on this option
* @param {APIMessageComponentEmoji} emoji The emoji to display on this option
* @returns {SelectMenuOption}
*/
setEmoji(emoji) {
if (typeof emoji === 'string') {
return super.setEmoji(Util.parseEmoji(emoji));
}
return super.setEmoji(emoji);
}
}

module.exports = SelectMenuOption;
10 changes: 7 additions & 3 deletions packages/discord.js/typings/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ import {
quote,
roleMention,
SelectMenuComponent as BuilderSelectMenuComponent,
SelectMenuOption as BuildersSelectMenuOption,
TextInputComponent as BuilderTextInputComponent,
spoiler,
strikethrough,
Expand Down Expand Up @@ -502,11 +503,11 @@ export class ButtonInteraction<Cached extends CacheType = CacheType> extends Mes
public inRawGuild(): this is ButtonInteraction<'raw'>;
}

export type ComponentEmojiResolvable = APIMessageComponentEmoji | string;
export type ComponentEmojiResolvable = APIMessageComponentEmoji | `<${'a' | ''}:${string}:${bigint}>`;

export class ButtonComponent extends BuilderButtonComponent {
public constructor(data?: ButtonComponentData | (Omit<APIButtonComponent, 'type'> & { type?: ComponentType.Button }));
public override setEmoji(emoji: string | ComponentEmojiResolvable): this;
public override setEmoji(emoji: ComponentEmojiResolvable): this;
}

export class SelectMenuComponent extends BuilderSelectMenuComponent {
Expand All @@ -515,6 +516,10 @@ export class SelectMenuComponent extends BuilderSelectMenuComponent {
);
}

export class SelectMenuOption extends BuildersSelectMenuOption {
public setEmoji(emoji: ComponentEmojiResolvable): this;
}

export class TextInputComponent extends BuilderTextInputComponent {
public constructor(data?: TextInputComponentData | APITextInputComponent);
}
Expand Down Expand Up @@ -5294,7 +5299,6 @@ export {
export {
UnsafeButtonComponent,
UnsafeSelectMenuComponent,
SelectMenuOption,
UnsafeSelectMenuOption,
MessageActionRowComponent,
UnsafeEmbed,
Expand Down
6 changes: 5 additions & 1 deletion packages/discord.js/typings/index.test-d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1358,7 +1358,11 @@ new SelectMenuComponent({

new ButtonComponent({
style: ButtonStyle.Danger,
});
})
.setEmoji('<a:foo:123>')
.setEmoji('<:foo:123>')
// @ts-expect-error
.setEmoji(':foobar:123');

// @ts-expect-error
new Embed().setColor('abc');
Expand Down

0 comments on commit 28b4c92

Please sign in to comment.