/
StringSelectMenuOptionBuilder.js
48 lines (42 loc) · 1.41 KB
/
StringSelectMenuOptionBuilder.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
'use strict';
const { SelectMenuOptionBuilder: BuildersSelectMenuOption, isJSONEncodable } = require('@discordjs/builders');
const { toSnakeCase } = require('../util/Transformers');
const { resolvePartialEmoji } = require('../util/Util');
/**
* Represents a select menu option builder.
* @extends {BuildersSelectMenuOption}
*/
class StringSelectMenuOptionBuilder extends BuildersSelectMenuOption {
constructor({ emoji, ...data } = {}) {
super(
toSnakeCase({
...data,
emoji: emoji && typeof emoji === 'string' ? resolvePartialEmoji(emoji) : emoji,
}),
);
}
/**
* Sets the emoji to display on this option
* @param {ComponentEmojiResolvable} emoji The emoji to display on this option
* @returns {StringSelectMenuOptionBuilder}
*/
setEmoji(emoji) {
if (typeof emoji === 'string') {
return super.setEmoji(resolvePartialEmoji(emoji));
}
return super.setEmoji(emoji);
}
/**
* Creates a new select menu option builder from JSON data
* @param {StringSelectMenuOptionBuilder|APISelectMenuOption} other The other data
* @returns {StringSelectMenuOptionBuilder}
*/
static from(other) {
return new this(isJSONEncodable(other) ? other.toJSON() : other);
}
}
module.exports = StringSelectMenuOptionBuilder;
/**
* @external BuildersSelectMenuOption
* @see {@link https://discord.js.org/docs/packages/builders/stable/SelectMenuOptionBuilder:Class}
*/