Skip to content
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

feat(StageChannel): add createStageInstance method & use better naming convention #5951

Merged
merged 4 commits into from
Jul 1, 2021
Merged
Show file tree
Hide file tree
Changes from 2 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: 7 additions & 8 deletions src/managers/StageInstanceManager.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,31 +28,30 @@ class StageInstanceManager extends BaseManager {

/**
* Options used to create a stage instance.
* @typedef {Object} CreateStageInstanceOptions
* @property {StageChannel|Snowflake} channel The stage channel whose instance is to be created
* @typedef {Object} StageInstanceCreateOptions
* @property {string} topic The topic of the stage instance
* @property {PrivacyLevel|number} [privacyLevel] The privacy level of the stage instance
*/

/**
* Creates a new stage instance.
* @param {CreateStageInstanceOptions} options The options to create the stage instance
* @param {StageChannel|Snowflake} channel The stage channel whose instance is to be created
iShibi marked this conversation as resolved.
Show resolved Hide resolved
* @param {StageInstanceCreateOptions} options The options to create the stage instance
* @returns {Promise<StageInstance>}
* @example
* // Create a stage instance
* guild.stageInstances.create({
* channel: '1234567890123456789',
* guild.stageInstances.create('1234567890123456789', {
* topic: 'A very creative topic',
* privacyLevel: 'GUILD_ONLY'
* })
* .then(stageInstance => console.log(stageInstance))
* .catch(console.error);
*/
async create(options) {
if (typeof options !== 'object') throw new TypeError('INVALID_TYPE', 'options', 'object', true);
let { channel, topic, privacyLevel } = options;
async create(channel, options) {
kyranet marked this conversation as resolved.
Show resolved Hide resolved
const channelID = this.guild.channels.resolveID(channel);
if (!channelID) throw new Error('STAGE_CHANNEL_RESOLVE');
if (typeof options !== 'object') throw new TypeError('INVALID_TYPE', 'options', 'object', true);
let { topic, privacyLevel } = options;

if (privacyLevel) privacyLevel = typeof privacyLevel === 'number' ? privacyLevel : PrivacyLevels[privacyLevel];

Expand Down
9 changes: 9 additions & 0 deletions src/structures/StageChannel.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,15 @@ class StageChannel extends BaseGuildVoiceChannel {
return this.guild.stageInstances.cache.find(stageInstance => stageInstance.channelID === this.id) ?? null;
}

/**
* Creates an instance of this stage channel.
iShibi marked this conversation as resolved.
Show resolved Hide resolved
* @param {StageInstanceCreateOptions} options The options to create the stage instance
* @returns {Promise<StageInstance>}
*/
createInstance(options) {
return this.guild.stageInstances.create(this.id, options);
}

/**
* Sets the RTC region of the channel.
* @name StageChannel#setRTCRegion
Expand Down
6 changes: 3 additions & 3 deletions typings/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1828,6 +1828,7 @@ declare module 'discord.js' {
public topic: string | null;
public type: 'stage';
public readonly instance: StageInstance | null;
public createInstance(options: StageInstanceCreateOptions): Promise<StageInstance>;
}

export class StageInstance extends Base {
Expand Down Expand Up @@ -2539,7 +2540,7 @@ declare module 'discord.js' {
export class StageInstanceManager extends BaseManager<Snowflake, StageInstance, StageInstanceResolvable> {
constructor(guild: Guild, iterable?: Iterable<any>);
public guild: Guild;
public create(options: CreateStageInstanceOptions): Promise<StageInstance>;
public create(channel: StageChannel | Snowflake, options: StageInstanceCreateOptions): Promise<StageInstance>;
public fetch(channel: StageChannel | Snowflake, options?: BaseFetchOptions): Promise<StageInstance>;
public edit(channel: StageChannel | Snowflake, options: StageInstanceEditOptions): Promise<StageInstance>;
public delete(channel: StageChannel | Snowflake): Promise<void>;
Expand Down Expand Up @@ -3120,8 +3121,7 @@ declare module 'discord.js' {
reason?: string;
}

interface CreateStageInstanceOptions {
channel: StageChannel | Snowflake;
interface StageInstanceCreateOptions {
topic: string;
privacyLevel?: PrivacyLevel | number;
}
Expand Down