mirror of
https://github.com/discordjs/discord.js.git
synced 2026-03-10 00:23:30 +01:00
Added deleting messages
This commit is contained in:
@@ -59,6 +59,8 @@ var Client = (function (_EventEmitter) {
|
||||
});
|
||||
};
|
||||
|
||||
// def sendMessage
|
||||
|
||||
Client.prototype.sendMessage = function sendMessage(where, content) {
|
||||
var options = arguments.length <= 2 || arguments[2] === undefined ? {} : arguments[2];
|
||||
var callback = arguments.length <= 3 || arguments[3] === undefined ? function (e, m) {} : arguments[3];
|
||||
@@ -81,6 +83,8 @@ var Client = (function (_EventEmitter) {
|
||||
});
|
||||
};
|
||||
|
||||
// def sendTTSMessage
|
||||
|
||||
Client.prototype.sendTTSMessage = function sendTTSMessage(where, content) {
|
||||
var callback = arguments.length <= 2 || arguments[2] === undefined ? function (e, m) {} : arguments[2];
|
||||
|
||||
@@ -96,6 +100,8 @@ var Client = (function (_EventEmitter) {
|
||||
});
|
||||
};
|
||||
|
||||
// def reply
|
||||
|
||||
Client.prototype.reply = function reply(where, content) {
|
||||
var options = arguments.length <= 2 || arguments[2] === undefined ? {} : arguments[2];
|
||||
var callback = arguments.length <= 3 || arguments[3] === undefined ? function (e, m) {} : arguments[3];
|
||||
@@ -126,6 +132,8 @@ var Client = (function (_EventEmitter) {
|
||||
});
|
||||
};
|
||||
|
||||
// def replyTTS
|
||||
|
||||
Client.prototype.replyTTS = function replyTTS(where, content) {
|
||||
var callback = arguments.length <= 2 || arguments[2] === undefined ? function () {} : arguments[2];
|
||||
|
||||
@@ -140,6 +148,27 @@ var Client = (function (_EventEmitter) {
|
||||
});
|
||||
};
|
||||
|
||||
Client.prototype.deleteMessage = function deleteMessage(msg) {
|
||||
var options = arguments.length <= 1 || arguments[1] === undefined ? {} : arguments[1];
|
||||
var callback = arguments.length <= 2 || arguments[2] === undefined ? function (e) {} : arguments[2];
|
||||
|
||||
var self = this;
|
||||
return new Promise(function (resolve, reject) {
|
||||
if (typeof options === "function") {
|
||||
// options is the callback
|
||||
callback = options;
|
||||
}
|
||||
|
||||
self.internal.deleteMessage(msg).then(function () {
|
||||
callback();
|
||||
resolve();
|
||||
})["catch"](function (e) {
|
||||
callback(e);
|
||||
reject(e);
|
||||
});
|
||||
});
|
||||
};
|
||||
|
||||
return Client;
|
||||
})(EventEmitter);
|
||||
|
||||
|
||||
@@ -184,6 +184,37 @@ var InternalClient = (function () {
|
||||
});
|
||||
};
|
||||
|
||||
InternalClient.prototype.deleteMessage = function deleteMessage(_message) {
|
||||
var options = arguments.length <= 1 || arguments[1] === undefined ? {} : arguments[1];
|
||||
|
||||
var self = this;
|
||||
return new Promise(function (resolve, reject) {
|
||||
|
||||
var message = self.resolver.resolveMessage(_message);
|
||||
|
||||
if (message) {
|
||||
var deleteMsg = function deleteMsg() {
|
||||
request.del(Endpoints.CHANNEL_MESSAGE(message.channel.id, message.id)).set("authorization", self.token).end(function (err, res) {
|
||||
if (err) {
|
||||
reject(new Error(err.response.text));
|
||||
} else {
|
||||
message.channel.messages.remove(message);
|
||||
resolve();
|
||||
}
|
||||
});
|
||||
};
|
||||
|
||||
if (options.wait) {
|
||||
setTimeout(deleteMsg, options.wait);
|
||||
} else {
|
||||
deleteMsg();
|
||||
}
|
||||
} else {
|
||||
reject(new Error("Supplied message did not resolve to a message!"));
|
||||
}
|
||||
});
|
||||
};
|
||||
|
||||
InternalClient.prototype.sendWS = function sendWS(object) {
|
||||
this.websocket.send(JSON.stringify(object));
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user