Skip to content

fix!: move crosspost() to GuildMessageManager #10703

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 15 additions & 0 deletions packages/discord.js/src/managers/GuildMessageManager.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
'use strict';

const { Routes } = require('discord-api-types/v10');
const MessageManager = require('./MessageManager');
const { DiscordjsTypeError, ErrorCodes } = require('../errors');

/**
* Manages API methods for messages in a guild and holds their cache.
Expand All @@ -12,6 +14,19 @@ class GuildMessageManager extends MessageManager {
* @name GuildMessageManager#channel
* @type {GuildTextBasedChannel}
*/

/**
* Publishes a message in an announcement channel to all channels following it, even if it's not cached.
* @param {MessageResolvable} message The message to publish
* @returns {Promise<Message>}
*/
async crosspost(message) {
const messageId = this.resolveId(message);
if (!messageId) throw new DiscordjsTypeError(ErrorCodes.InvalidType, 'message', 'MessageResolvable');

const data = await this.client.rest.post(Routes.channelMessageCrosspost(this.channel.id, messageId));
return this.cache.get(data.id) ?? this._add(data);
}
}

module.exports = GuildMessageManager;
13 changes: 0 additions & 13 deletions packages/discord.js/src/managers/MessageManager.js
Original file line number Diff line number Diff line change
Expand Up @@ -196,19 +196,6 @@ class MessageManager extends CachedManager {
return this._add(d);
}

/**
* Publishes a message in an announcement channel to all channels following it, even if it's not cached.
* @param {MessageResolvable} message The message to publish
* @returns {Promise<Message>}
*/
async crosspost(message) {
message = this.resolveId(message);
if (!message) throw new DiscordjsTypeError(ErrorCodes.InvalidType, 'message', 'MessageResolvable');

const data = await this.client.rest.post(Routes.channelMessageCrosspost(this.channel.id, message));
return this.cache.get(data.id) ?? this._add(data);
}

/**
* Pins a message to the channel's pinned messages, even if it's not cached.
* @param {MessageResolvable} message The message to pin
Expand Down
Loading