mirror of
https://github.com/ION606/custom_discordjs.git
synced 2026-05-14 22:26:54 +00:00
added message select menus
This commit is contained in:
@@ -1,4 +1,36 @@
|
||||
// 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';
|
||||
|
||||
export class Button {
|
||||
/** @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) {
|
||||
obj[i] = this[i];
|
||||
}
|
||||
return obj;
|
||||
}
|
||||
|
||||
constructor() {}
|
||||
}
|
||||
@@ -0,0 +1,7 @@
|
||||
export const MessageButtonStyles = Object.freeze({
|
||||
PRIMARY: 1,
|
||||
SECONDARY: 2,
|
||||
SUCCESS: 3,
|
||||
DANGER: 4,
|
||||
LINK: 5
|
||||
});
|
||||
@@ -0,0 +1,112 @@
|
||||
import {messageChannelTypes} from '../messages/messageChannelTypes.js';
|
||||
|
||||
export class StringMenuComponent {
|
||||
/** @type {String} */
|
||||
label;
|
||||
|
||||
/** @type {String} */
|
||||
value;
|
||||
|
||||
/** @type {String} */
|
||||
description;
|
||||
|
||||
/** @type {{id: String, name: String, animated: Boolean}} */
|
||||
emoji;
|
||||
|
||||
/** @type {Boolean} */
|
||||
default;
|
||||
|
||||
toJSON() {
|
||||
const obj = {};
|
||||
for (const k in this) {
|
||||
obj[k] = this[k];
|
||||
}
|
||||
return obj;
|
||||
}
|
||||
}
|
||||
|
||||
export const SelectMenuTypes = Object.freeze({
|
||||
TEXT: 3,
|
||||
USER: 5,
|
||||
ROLE: 6,
|
||||
MENTIONABLE: 7,
|
||||
CHANNELS: 8
|
||||
});
|
||||
|
||||
|
||||
class BaseSelectMenu {
|
||||
#type;
|
||||
|
||||
/** @type {String} */
|
||||
custom_id;
|
||||
|
||||
/** @type {Boolean} */
|
||||
disabled;
|
||||
|
||||
/** @type {Number} */
|
||||
min_values;
|
||||
|
||||
/** @type {Number} */
|
||||
max_values;
|
||||
|
||||
/** @type {String} */
|
||||
placeholder;
|
||||
|
||||
toObj() {
|
||||
if (!this.custom_id) throw "PLEASE ENTER A CUSTOM ID!";
|
||||
var obj = { type: this.#type };
|
||||
for (const k in this) {
|
||||
obj[k] = this[k];
|
||||
}
|
||||
|
||||
return obj;
|
||||
}
|
||||
|
||||
constructor(type) { this.#type = type; this.min_values = 1; this.max_values = 1; }
|
||||
}
|
||||
|
||||
export class StringSelectMenu extends BaseSelectMenu {
|
||||
/** @type {StringMenuComponent[]} */
|
||||
options;
|
||||
|
||||
toObj() {
|
||||
const obj = super.toObj();
|
||||
obj["options"] = [];
|
||||
for (const k of this.options) {
|
||||
obj["options"].push(k.toJSON());
|
||||
}
|
||||
return obj;
|
||||
}
|
||||
|
||||
constructor() { super(SelectMenuTypes.TEXT); this.options = []; }
|
||||
}
|
||||
|
||||
export class ChannelSelectMenu extends BaseSelectMenu {
|
||||
/** @type { messageChannelTypes[] } */
|
||||
options;
|
||||
|
||||
toObj() {
|
||||
const obj = super.toObj();
|
||||
obj["channel_types"] = [];
|
||||
for (const k of this.options) {
|
||||
obj["channel_types"].push(k);
|
||||
}
|
||||
}
|
||||
|
||||
constructor() { super(SelectMenuTypes.CHANNELS); this.options = []; }
|
||||
}
|
||||
|
||||
|
||||
export class userSelectMenu extends BaseSelectMenu {
|
||||
constructor() { super(SelectMenuTypes.USER); }
|
||||
}
|
||||
|
||||
|
||||
export class RoleSelectMenu extends BaseSelectMenu {
|
||||
constructor() { super(SelectMenuTypes.ROLE); }
|
||||
}
|
||||
|
||||
|
||||
export class MentionableSelectMenu extends BaseSelectMenu {
|
||||
constructor() { super(SelectMenuTypes.MENTIONABLE); }
|
||||
}
|
||||
Reference in New Issue
Block a user