mirror of
https://github.com/discordjs/discord.js.git
synced 2026-03-10 00:23:30 +01:00
Added get channel logs
This commit is contained in:
@@ -251,6 +251,44 @@ var InternalClient = (function () {
|
||||
});
|
||||
};
|
||||
|
||||
InternalClient.prototype.getChannelLogs = function getChannelLogs(_channel) {
|
||||
var limit = arguments.length <= 1 || arguments[1] === undefined ? 500 : arguments[1];
|
||||
var options = arguments.length <= 2 || arguments[2] === undefined ? {} : arguments[2];
|
||||
|
||||
var self = this;
|
||||
return new Promise(function (resolve, reject) {
|
||||
|
||||
self.resolver.resolveChannel(_channel).then(next)["catch"](function (e) {
|
||||
return reject(new Error("couldn't resolve to channel - " + e));
|
||||
});
|
||||
|
||||
function next(channel) {
|
||||
|
||||
if (options.before) options.before = self.resolver.resolveMessage(options.before);
|
||||
if (options.after) options.after = self.resolver.resolveMessage(options.after);
|
||||
|
||||
var params = [];
|
||||
if (options.before) params.push("before=" + options.before.id);
|
||||
if (options.after) params.push("after=" + options.after.id);
|
||||
|
||||
var joinedParams = params.join();
|
||||
if (joinedParams !== "") joinedParams = "&" + params.join();
|
||||
|
||||
request.get(Endpoints.CHANNEL_MESSAGES(channel.id) + "?limit=" + limit + joinedParams).set("authorization", self.token).end(function (err, res) {
|
||||
if (err) {
|
||||
reject(new Error(err.response.text));
|
||||
} else {
|
||||
var logs = [];
|
||||
res.body.forEach(function (msg) {
|
||||
logs.push(channel.messages.add(new Message(msg, channel, self.client)));
|
||||
});
|
||||
resolve(logs);
|
||||
}
|
||||
});
|
||||
}
|
||||
});
|
||||
};
|
||||
|
||||
InternalClient.prototype.sendWS = function sendWS(object) {
|
||||
this.websocket.send(JSON.stringify(object));
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user