mirror of
https://github.com/discordjs/discord.js.git
synced 2026-03-12 09:33:32 +01:00
Fixed awaiting
This commit is contained in:
@@ -804,6 +804,25 @@ var Client = (function (_EventEmitter) {
|
||||
});
|
||||
};
|
||||
|
||||
// def awaitResponse
|
||||
|
||||
Client.prototype.awaitResponse = function awaitResponse(msg) {
|
||||
var _this = this;
|
||||
|
||||
var callback = arguments.length <= 1 || arguments[1] === undefined ? function (e, newMsg) {} : arguments[1];
|
||||
|
||||
return new Promise(function (resolve, reject) {
|
||||
|
||||
_this.internal.awaitResponse(msg).then(function (newMsg) {
|
||||
resolve(newMsg);
|
||||
callback(null, newMsg);
|
||||
})["catch"](function (e) {
|
||||
callback(e);
|
||||
reject(e);
|
||||
});
|
||||
});
|
||||
};
|
||||
|
||||
Client.prototype.setStatusIdle = function setStatusIdle() {
|
||||
this.setStatus("idle");
|
||||
};
|
||||
|
||||
@@ -83,7 +83,7 @@ var InternalClient = (function () {
|
||||
return;
|
||||
}
|
||||
|
||||
var awaitID = msg.channel.id + msg.id;
|
||||
var awaitID = msg.channel.id + msg.author.id;
|
||||
|
||||
if (!_this.messageAwaits[awaitID]) {
|
||||
_this.messageAwaits[awaitID] = [];
|
||||
@@ -1274,11 +1274,11 @@ var InternalClient = (function () {
|
||||
if (channel) {
|
||||
var msg = channel.messages.add(new Message(data, channel, client));
|
||||
|
||||
if (self.messageAwaits[channel.id + msg.id]) {
|
||||
self.messageAwaits[channel.id + msg.id].map(function (fn) {
|
||||
return fn();
|
||||
if (self.messageAwaits[channel.id + msg.author.id]) {
|
||||
self.messageAwaits[channel.id + msg.author.id].map(function (fn) {
|
||||
return fn(msg);
|
||||
});
|
||||
self.messageAwaits[channel.id + msg.id] = null;
|
||||
self.messageAwaits[channel.id + msg.author.id] = null;
|
||||
client.emit("message", msg, true); //2nd param is isAwaitedMessage
|
||||
} else {
|
||||
client.emit("message", msg);
|
||||
|
||||
Reference in New Issue
Block a user