@hedystia/discord
Version:
JavaScript library for interacting with the Discord API
54 lines (50 loc) • 2.08 kB
JavaScript
const MessagePayload = require("../Util/MessagePayload");
const Channel = require("./Channel");
/**
* A class representing a forum channel on Discord.
* @class
* @extends Channel
*/
class ForumChannel extends Channel {
/**
* @constructor
* @param {Object} [data] - The data for the forum channel
* @param {string} [guildId] - The ID of the guild that the channel belongs to
* @param {Client} [client] - The client that instantiated the channel
*/
constructor(data = {}, guildId, client) {
super(data, guildId, client);
this.availableTags = data.available_tags ?? null;
this.appliedTags = data.applied_tags ?? null;
this.defaultReactionEmoji = data.default_reaction_emoji ?? null;
this.defaultThreadRateLimitPerUser = data.default_thread_rate_limit_per_user ?? null;
this.defaultSortOrder = data.default_sort_order ?? null;
this.defaultForumLayout = data.default_forum_layout ?? null;
}
/**
* Creates a new thread in the forum channel.
* @async
* @param {Object} [options] - The options for the thread
* @param {string} [options.name] - The name of the thread
* @param {number} [options.autoArchiveDuration] - The duration in minutes to automatically archive the thread
* @param {number} [options.rateLimitPerUser] - The rate limit per user for the thread in seconds
* @param {string} [options.reason] - The reason for creating the thread
* @param {Message} [options.message] - The message to use as a basis for the thread
* @returns {Promise<Object>} The thread data
*/
async createThread(options = {}) {
const {reason, message} = options;
let body = {
name: options.name ?? undefined,
auto_archive_duration: options.autoArchiveDuration ?? undefined,
rate_limit_per_user: options.rateLimitPerUser ?? undefined,
};
if (message) {
body = Object.assign(await new MessagePayload.create(message), body);
return body;
} else {
return body;
}
}
}
module.exports = ForumChannel;