/
ButtonBuilder.js
46 lines (40 loc) · 1.27 KB
/
ButtonBuilder.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
'use strict';
const { ButtonBuilder: BuildersButton, isJSONEncodable } = require('@discordjs/builders');
const { toSnakeCase } = require('../util/Transformers');
const { resolvePartialEmoji } = require('../util/Util');
/**
* Represents a button builder.
* @extends {BuildersButton}
*/
class ButtonBuilder extends BuildersButton {
constructor({ emoji, ...data } = {}) {
super(toSnakeCase({ ...data, emoji: emoji && typeof emoji === 'string' ? resolvePartialEmoji(emoji) : emoji }));
}
/**
* Sets the emoji to display on this button
* @param {string|APIMessageComponentEmoji} emoji The emoji to display on this button
* @returns {ButtonBuilder}
*/
setEmoji(emoji) {
if (typeof emoji === 'string') {
return super.setEmoji(resolvePartialEmoji(emoji));
}
return super.setEmoji(emoji);
}
/**
* Creates a new button builder from JSON data
* @param {JSONEncodable<APIButtonComponent>|APIButtonComponent} other The other data
* @returns {ButtonBuilder}
*/
static from(other) {
if (isJSONEncodable(other)) {
return new this(other.toJSON());
}
return new this(other);
}
}
module.exports = ButtonBuilder;
/**
* @external BuildersButton
* @see {@link https://discord.js.org/#/docs/builders/main/class/ButtonBuilder}
*/