Skip to content

Commit

Permalink
fix: make error message more accurate
Browse files Browse the repository at this point in the history
  • Loading branch information
ImRodry committed Sep 5, 2021
1 parent 1183a63 commit 0792a80
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 10 deletions.
2 changes: 1 addition & 1 deletion src/errors/Messages.js
Expand Up @@ -92,7 +92,7 @@ const Messages = {
GUILD_OWNED: 'Guild is owned by the client.',
GUILD_MEMBERS_TIMEOUT: "Members didn't arrive in time.",
GUILD_UNCACHED_ME: 'The client user as a member of this guild is uncached.',
NO_GUILD_CHANNEL: 'Could not find the channel where this message came from! It may have been deleted.',
CHANNEL_NOT_CACHED: 'Could not find the channel where this message came from in the cache!',
STAGE_CHANNEL_RESOLVE: 'Could not resolve channel to a stage channel.',

INVALID_TYPE: (name, expected, an = false) => `Supplied ${name} is not a${an ? 'n' : ''} ${expected}.`,
Expand Down
18 changes: 9 additions & 9 deletions src/structures/Message.js
Expand Up @@ -632,7 +632,7 @@ class Message extends Base {
* .catch(console.error);
*/
edit(options) {
if (!this.channel) return Promise.reject(new Error('NO_GUILD_CHANNEL'));
if (!this.channel) return Promise.reject(new Error('CHANNEL_NOT_CACHED'));
return this.channel.messages.edit(this, options);
}

Expand All @@ -648,7 +648,7 @@ class Message extends Base {
* }
*/
crosspost() {
if (!this.channel) return Promise.reject(new Error('NO_GUILD_CHANNEL'));
if (!this.channel) return Promise.reject(new Error('CHANNEL_NOT_CACHED'));
return this.channel.messages.crosspost(this.id);
}

Expand All @@ -662,7 +662,7 @@ class Message extends Base {
* .catch(console.error)
*/
async pin() {
if (!this.channel) throw new Error('NO_GUILD_CHANNEL');
if (!this.channel) throw new Error('CHANNEL_NOT_CACHED');
await this.channel.messages.pin(this.id);
return this;
}
Expand All @@ -677,7 +677,7 @@ class Message extends Base {
* .catch(console.error)
*/
async unpin() {
if (!this.channel) throw new Error('NO_GUILD_CHANNEL');
if (!this.channel) throw new Error('CHANNEL_NOT_CACHED');
await this.channel.messages.unpin(this.id);
return this;
}
Expand All @@ -698,7 +698,7 @@ class Message extends Base {
* .catch(console.error);
*/
async react(emoji) {
if (!this.channel) throw new Error('NO_GUILD_CHANNEL');
if (!this.channel) throw new Error('CHANNEL_NOT_CACHED');
emoji = this.client.emojis.resolveIdentifier(emoji);
await this.channel.messages.react(this.id, emoji);
return this.client.actions.MessageReactionAdd.handle({
Expand All @@ -719,7 +719,7 @@ class Message extends Base {
* .catch(console.error);
*/
async delete() {
if (!this.channel) throw new Error('NO_GUILD_CHANNEL');
if (!this.channel) throw new Error('CHANNEL_NOT_CACHED');
await this.channel.messages.delete(this.id);
return this;
}
Expand All @@ -742,7 +742,7 @@ class Message extends Base {
* .catch(console.error);
*/
reply(options) {
if (!this.channel) return Promise.reject(new Error('NO_GUILD_CHANNEL'));
if (!this.channel) return Promise.reject(new Error('CHANNEL_NOT_CACHED'));
let data;

if (options instanceof MessagePayload) {
Expand Down Expand Up @@ -774,7 +774,7 @@ class Message extends Base {
* @returns {Promise<ThreadChannel>}
*/
startThread(options = {}) {
if (!this.channel) return Promise.reject(new Error('NO_GUILD_CHANNEL'));
if (!this.channel) return Promise.reject(new Error('CHANNEL_NOT_CACHED'));
if (!['GUILD_TEXT', 'GUILD_NEWS'].includes(this.channel.type)) {
return Promise.reject(new Error('MESSAGE_THREAD_PARENT'));
}
Expand All @@ -788,7 +788,7 @@ class Message extends Base {
* @returns {Promise<Message>}
*/
fetch(force = true) {
if (!this.channel) return Promise.reject(new Error('NO_GUILD_CHANNEL'));
if (!this.channel) return Promise.reject(new Error('CHANNEL_NOT_CACHED'));
return this.channel.messages.fetch(this.id, { force });
}

Expand Down

0 comments on commit 0792a80

Please sign in to comment.