slash-create-modify
Version:
Create and sync Discord slash commands!
68 lines (67 loc) • 2.46 kB
JavaScript
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.Message = void 0;
const user_1 = require("./user");
/** Represents a Discord message. */
class Message {
/**
* @param data The data for the message
* @param ctx The instantiating context
*/
constructor(data, creator, ctx) {
if (ctx)
this._ctx = ctx;
this.id = data.id;
this.type = data.type;
this.content = data.content;
this.channelID = data.channel_id;
this.components = data.components || [];
this.author = new user_1.User(data.author, creator);
this.attachments = data.attachments;
this.embeds = data.embeds;
this.mentions = data.mentions.map((user) => new user_1.User(user, creator));
this.roleMentions = data.mention_roles;
this.mentionedEveryone = data.mention_everyone;
this.tts = data.tts;
this.pinned = data.pinned;
this.timestamp = Date.parse(data.timestamp);
if (data.edited_timestamp)
this.editedTimestamp = Date.parse(data.edited_timestamp);
this.flags = data.flags;
if (data.message_reference)
this.messageReference = {
channelID: data.message_reference.channel_id,
guildID: data.message_reference.guild_id,
messageID: data.message_reference.message_id
};
this.webhookID = data.webhook_id;
if (data.interaction)
this.interaction = {
id: data.interaction.id,
type: data.interaction.type,
name: data.interaction.name,
user: new user_1.User(data.interaction.user, creator)
};
}
/**
* Edits this message.
* @param content The content of the message
* @param options The message options
*/
edit(content, options) {
if (!this._ctx)
throw new Error('This message was not created from a command context.');
return this._ctx.edit(this.id, content, options);
}
/** Deletes this message. */
delete() {
if (!this._ctx)
throw new Error('This message was not created from a command context.');
return this._ctx.delete(this.id);
}
/** @hidden */
toString() {
return `[Message ${this.id}]`;
}
}
exports.Message = Message;