Add client.getMessage() (#428)

* Add client.getMessage

* Add shortcuts

* build it..

* Add missing ~ in note docs

* ............
This commit is contained in:
Manuel Kraus
2016-06-16 00:31:02 +02:00
committed by abal
parent 0f4566dd23
commit 0e4612d7ab
11 changed files with 212 additions and 67 deletions

View File

@@ -788,6 +788,34 @@ export default class InternalClient {
});
}
// def getMessage
getMessage(_channel, messageID) {
return this.resolver.resolveChannel(_channel)
.then(channel => {
if(!this.user.bot) {
return Promise.reject(new Error("Only OAuth bot accounts can use this function"));
}
if(!(channel instanceof TextChannel || channel instanceof PMChannel)) {
return Promise.reject(new Error("Provided channel is not a Text or PMChannel"));
}
var msg = channel.messages.get("id", messageID);
if(msg) {
return Promise.resolve(msg);
}
return this.apiRequest(
"get",
`${Endpoints.CHANNEL_MESSAGES(channel.id)}/${messageID}`,
true
)
.then(res => channel.messages.add(
new Message(res, channel, this.client)
));
})
}
// def getBans
getBans(server) {
server = this.resolver.resolveServer(server);