mirror of
https://github.com/discordjs/discord.js.git
synced 2026-03-09 16:13:31 +01:00
Make FetchMessage work for non-bot users (#1291)
* [WIP] make fetchMessage work for normal users wip * Actual thing * not WIP anymore better docs * oops * better stuff * Update TextBasedChannel.js * Update TextBasedChannel.js * Update TextBasedChannel.js
This commit is contained in:
committed by
Schuyler Cebulskie
parent
2349238f69
commit
64ce829ab2
@@ -181,7 +181,8 @@ class TextBasedChannel {
|
||||
|
||||
/**
|
||||
* Gets a single message from this channel, regardless of it being cached or not.
|
||||
* <warn>This is only available when using a bot account.</warn>
|
||||
* Since the single message fetching endpoint is reserved for bot accounts, this abstracts
|
||||
* {@link #fetchMessages} to obtain the single message when using a user account.
|
||||
* @param {Snowflake} messageID ID of the message to get
|
||||
* @returns {Promise<Message>}
|
||||
* @example
|
||||
@@ -191,6 +192,13 @@ class TextBasedChannel {
|
||||
* .catch(console.error);
|
||||
*/
|
||||
fetchMessage(messageID) {
|
||||
if (!this.client.user.bot) {
|
||||
return this.fetchMessages({ limit: 1, around: messageID }).then(messages => {
|
||||
const msg = messages.first();
|
||||
if (msg.id !== messageID) throw new Error('Message not found.');
|
||||
return msg;
|
||||
});
|
||||
}
|
||||
return this.client.rest.methods.getChannelMessage(this, messageID).then(data => {
|
||||
const msg = data instanceof Message ? data : new Message(this, data, this.client);
|
||||
this._cacheMessage(msg);
|
||||
|
||||
Reference in New Issue
Block a user