mirror of
https://github.com/discordjs/discord.js.git
synced 2026-03-13 10:03:31 +01:00
Add client.getMessage() (#428)
* Add client.getMessage * Add shortcuts * build it.. * Add missing ~ in note docs * ............
This commit is contained in:
@@ -611,6 +611,34 @@ export default class Client extends EventEmitter {
|
||||
.then(dataCallback(callback), errorCallback(callback));
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets a single message of a server
|
||||
* @param {ChannelResolvable} channel to get the message from
|
||||
* @param {function(err: Error, msg: Message} [callback] callback to the method
|
||||
* @returns {Promise<Message, Error>} Resolves with a message if the request was successful, otherwise rejects with an error.
|
||||
* @example
|
||||
* // get message object off a snowflake and log its content - callback
|
||||
* client.getMessage(channel, '192696158886428672', function(err, msg) {
|
||||
* if(!err) {
|
||||
* console.log(msg.content);
|
||||
* } else {
|
||||
* console.log("couldn't get the message");
|
||||
* }
|
||||
* }
|
||||
* @example
|
||||
* //get message object off a snowflake and log its content - promise
|
||||
* client.getMessage(channel, '192696158886428672')
|
||||
* .then(msg => {
|
||||
* console.log(msg.content);
|
||||
* })
|
||||
* .catch(err => console.log("couldn't get the message"));
|
||||
*/
|
||||
|
||||
getMessage(channel, messageID, callback = (/*err, msg*/) => { }) {
|
||||
return this.internal.getMessage(channel, messageID)
|
||||
.then(dataCallback(callback), errorCallback(callback));
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the banned users of a server (if the client has permission to)
|
||||
* @param {ServerResolvable} server server to get banned users of
|
||||
|
||||
@@ -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);
|
||||
|
||||
Reference in New Issue
Block a user