-
-
Notifications
You must be signed in to change notification settings - Fork 3.9k
/
ActionRow.js
48 lines (41 loc) · 1.25 KB
/
ActionRow.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 { deprecate } = require('node:util');
const { isJSONEncodable } = require('@discordjs/builders');
const Component = require('./Component');
const { createComponent } = require('../util/Components');
/**
* Represents an action row
* @extends {Component}
*/
class ActionRow extends Component {
constructor({ components, ...data }) {
super(data);
/**
* The components in this action row
* @type {Component[]}
* @readonly
*/
this.components = components.map(c => createComponent(c));
}
/**
* Creates a new action row builder from JSON data
* @param {JSONEncodable<APIActionRowComponent>|APIActionRowComponent} other The other data
* @returns {ActionRowBuilder}
* @deprecated Use {@link ActionRowBuilder.from} instead.
*/
static from(other) {
if (isJSONEncodable(other)) {
return new this(other.toJSON());
}
return new this(other);
}
/**
* Returns the API-compatible JSON for this component
* @returns {APIActionRowComponent}
*/
toJSON() {
return { ...this.data, components: this.components.map(c => c.toJSON()) };
}
}
ActionRow.from = deprecate(ActionRow.from, 'ActionRow.from() is deprecated. Use ActionRowBuilder.from() instead.');
module.exports = ActionRow;