mirror of
https://github.com/discordjs/discord.js.git
synced 2026-03-11 00:53:31 +01:00
add embed support! (#894)
* add embed support! * document message embeds * make gawdl3y happy * make edit great again * make docs better * Update Message.js * Update TextBasedChannel.js * Update TextBasedChannel.js
This commit is contained in:
committed by
Schuyler Cebulskie
parent
ee3a03f707
commit
27270a3bad
@@ -48,7 +48,7 @@ class RESTMethods {
|
||||
return this.rest.makeRequest('get', Constants.Endpoints.botGateway, true);
|
||||
}
|
||||
|
||||
sendMessage(channel, content, { tts, nonce, disableEveryone, split } = {}, file = null) {
|
||||
sendMessage(channel, content, { tts, nonce, embed, disableEveryone, split } = {}, file = null) {
|
||||
return new Promise((resolve, reject) => {
|
||||
if (typeof content !== 'undefined') content = this.rest.client.resolver.resolveString(content);
|
||||
|
||||
@@ -62,15 +62,15 @@ class RESTMethods {
|
||||
|
||||
if (channel instanceof User || channel instanceof GuildMember) {
|
||||
this.createDM(channel).then(chan => {
|
||||
this._sendMessageRequest(chan, content, file, tts, nonce, resolve, reject);
|
||||
this._sendMessageRequest(chan, content, file, tts, nonce, embed, resolve, reject);
|
||||
}, reject);
|
||||
} else {
|
||||
this._sendMessageRequest(channel, content, file, tts, nonce, resolve, reject);
|
||||
this._sendMessageRequest(channel, content, file, tts, nonce, embed, resolve, reject);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
_sendMessageRequest(channel, content, file, tts, nonce, resolve, reject) {
|
||||
_sendMessageRequest(channel, content, file, tts, nonce, embed, resolve, reject) {
|
||||
if (content instanceof Array) {
|
||||
const datas = [];
|
||||
let promise = this.rest.makeRequest('post', Constants.Endpoints.channelMessages(channel.id), true, {
|
||||
@@ -83,7 +83,7 @@ class RESTMethods {
|
||||
promise = promise.then(data => {
|
||||
datas.push(data);
|
||||
return this.rest.makeRequest('post', Constants.Endpoints.channelMessages(channel.id), true, {
|
||||
content: content[i2], tts, nonce,
|
||||
content: content[i2], tts, nonce, embed,
|
||||
}, file);
|
||||
}, reject);
|
||||
} else {
|
||||
@@ -95,7 +95,7 @@ class RESTMethods {
|
||||
}
|
||||
} else {
|
||||
this.rest.makeRequest('post', Constants.Endpoints.channelMessages(channel.id), true, {
|
||||
content, tts, nonce,
|
||||
content, tts, nonce, embed,
|
||||
}, file)
|
||||
.then(data => resolve(this.rest.client.actions.MessageCreate.handle(data).message), reject);
|
||||
}
|
||||
@@ -122,10 +122,10 @@ class RESTMethods {
|
||||
);
|
||||
}
|
||||
|
||||
updateMessage(message, content) {
|
||||
updateMessage(message, content, { embed } = {}) {
|
||||
content = this.rest.client.resolver.resolveString(content);
|
||||
return this.rest.makeRequest('patch', Constants.Endpoints.channelMessage(message.channel.id, message.id), true, {
|
||||
content,
|
||||
content, embed,
|
||||
}).then(data => this.rest.client.actions.MessageUpdate.handle(data).updated);
|
||||
}
|
||||
|
||||
|
||||
@@ -340,9 +340,16 @@ class Message {
|
||||
return this.mentions.users.has(data) || this.mentions.channels.has(data) || this.mentions.roles.has(data);
|
||||
}
|
||||
|
||||
/**
|
||||
* Options that can be passed into editMessage
|
||||
* @typedef {Object} MessageEditOptions
|
||||
* @property {Object} [embed] An embed to be added/edited
|
||||
*/
|
||||
|
||||
/**
|
||||
* Edit the content of the message
|
||||
* @param {StringResolvable} content The new content for the message
|
||||
* @param {MessageEditOptions} [options={}] The options to provide
|
||||
* @returns {Promise<Message>}
|
||||
* @example
|
||||
* // update the content of a message
|
||||
@@ -350,8 +357,8 @@ class Message {
|
||||
* .then(msg => console.log(`Updated the content of a message from ${msg.author}`))
|
||||
* .catch(console.error);
|
||||
*/
|
||||
edit(content) {
|
||||
return this.client.rest.methods.updateMessage(this, content);
|
||||
edit(content, options = {}) {
|
||||
return this.client.rest.methods.updateMessage(this, content, options);
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -28,6 +28,8 @@ class TextBasedChannel {
|
||||
* @typedef {Object} MessageOptions
|
||||
* @property {boolean} [tts=false] Whether or not the message should be spoken aloud
|
||||
* @property {string} [nonce=''] The nonce for the message
|
||||
* @property {Object} [embed] An embed for the message
|
||||
* (see [here](https://discordapp.com/developers/docs/resources/channel#embed-object) for more details)
|
||||
* @property {boolean} [disableEveryone=this.client.options.disableEveryone] Whether or not @everyone and @here
|
||||
* should be replaced with plain-text
|
||||
* @property {boolean|SplitOptions} [split=false] Whether or not the message should be split into multiple messages if
|
||||
|
||||
Reference in New Issue
Block a user