Use APIModule directly to edit messages

This commit is contained in:
Samuel Elliott 2018-04-25 23:57:07 +01:00
parent 5e8579e4dc
commit 34ebab7c21
No known key found for this signature in database
GPG Key ID: 8420C7CDE43DC4D6
1 changed files with 9 additions and 3 deletions

View File

@ -215,15 +215,21 @@ export class DefaultMessage extends Message {
/**
* Programmatically update the message's content.
* TODO: how do we know if the message was updated successfully?
* @param {String} content The message's new content
* @param {Boolean} parse Whether to parse the message or update it as it is
* @return {Promise}
*/
edit(content, parse = false) {
async edit(content, parse = false) {
if (this.author !== DiscordApi.currentUser) throw new Error('Cannot edit messages sent by other users.');
if (parse) content = Modules.MessageParser.parse(this.discordObject, content);
else content = {content};
Modules.MessageActions.editMessage(this.channelId, this.id, content);
const response = await Modules.APIModule.patch({
url: `${Modules.DiscordConstants.Endpoints.MESSAGES(this.channelId)}/${this.id}`,
body: content
});
this.discordObject = Modules.MessageStore.getMessage(this.id, response.body.id);
}
/**