2023-04-08 16:33:58 -04:00
|
|
|
// https://github.com/discordjs/discord-api-types/blob/main/rest/v10/index.ts
|
|
|
|
|
// https://discord.com/developers/docs/interactions/message-components
|
|
|
|
|
import {MessageButtonStyles} from './ButtonStyles.js';
|
2023-04-07 20:35:03 -04:00
|
|
|
|
|
|
|
|
export class Button {
|
2023-04-08 16:33:58 -04:00
|
|
|
/** @type {MessageButtonStyles} */
|
|
|
|
|
style;
|
|
|
|
|
|
|
|
|
|
/** @type {String} */
|
|
|
|
|
label;
|
|
|
|
|
|
|
|
|
|
/** @type {{name: String, id: String, animated: Boolean}} */
|
|
|
|
|
emoji;
|
|
|
|
|
|
|
|
|
|
/** @type {String} */
|
|
|
|
|
custom_id;
|
|
|
|
|
|
|
|
|
|
/** @type {String} */
|
|
|
|
|
url;
|
|
|
|
|
|
|
|
|
|
/** @type {String} */
|
|
|
|
|
label;
|
|
|
|
|
|
|
|
|
|
/** @type {Boolean} */
|
|
|
|
|
disabled;
|
|
|
|
|
|
|
|
|
|
toObj() {
|
|
|
|
|
var obj = {type: 2};
|
|
|
|
|
for (const i in this) {
|
2023-04-16 19:50:45 -04:00
|
|
|
if (i == "url" && this.style != MessageButtonStyles.LINK) {
|
|
|
|
|
if (this.url != undefined) throw "CUSTOM ID MISSING";
|
|
|
|
|
}
|
|
|
|
|
if (i == "custom_id" && this.style == MessageButtonStyles.LINK) {
|
|
|
|
|
if (this.custom_id != undefined) throw "BUTTONS OF TYPE \"LINK\" CAN NOT HAVE A CUSTOM ID";
|
|
|
|
|
}
|
2023-04-08 16:33:58 -04:00
|
|
|
obj[i] = this[i];
|
|
|
|
|
}
|
|
|
|
|
return obj;
|
|
|
|
|
}
|
2023-04-07 20:35:03 -04:00
|
|
|
|
2023-04-16 19:50:45 -04:00
|
|
|
/**
|
|
|
|
|
* @param {MessageButtonStyles} style
|
|
|
|
|
*/
|
|
|
|
|
constructor(style = undefined) { this.style = style; }
|
2023-04-07 20:35:03 -04:00
|
|
|
}
|