Merge branch 'threads'

This commit is contained in:
Yuzu 2022-07-03 15:50:01 -05:00
commit aba8f8bd5a

View File

@ -10,17 +10,29 @@ import Invite from "../Invite.ts";
import * as Routes from "../../util/Routes.ts"; import * as Routes from "../../util/Routes.ts";
/** /**
* Represent the options object to create a Thread Channel * Represent the options object to create a thread channel
* @link https://discord.com/developers/docs/resources/channel#start-thread-without-message * @link https://discord.com/developers/docs/resources/channel#start-thread-without-message
*/ */
export interface ThreadCreateOptions { export interface ThreadCreateOptions {
name: string; name: string;
autoArchiveDuration: 60 | 1440 | 4320 | 10080; autoArchiveDuration?: 60 | 1440 | 4320 | 10080;
type: 10 | 11 | 12; type: 10 | 11 | 12;
invitable?: boolean; invitable?: boolean;
rateLimitPerUser?: number;
reason?: string; reason?: string;
} }
/**
* Represents the option object to create a thread channel from a message
* @link https://discord.com/developers/docs/resources/channel#start-thread-from-message
* */
export interface ThreadCreateOptions {
name: string;
autoArchiveDuration?: 60 | 1440 | 4320 | 10080;
rateLimitPerUser?: number;
messageId: Snowflake;
}
export class GuildChannel extends BaseChannel implements Model { export class GuildChannel extends BaseChannel implements Model {
constructor(session: Session, data: DiscordChannel, guildId: Snowflake) { constructor(session: Session, data: DiscordChannel, guildId: Snowflake) {
super(session, data); super(session, data);
@ -84,11 +96,16 @@ export class GuildChannel extends BaseChannel implements Model {
const thread = await this.session.rest.runMethod<DiscordChannel>( const thread = await this.session.rest.runMethod<DiscordChannel>(
this.session.rest, this.session.rest,
"POST", "POST",
Routes.CHANNEL_CREATE_THREAD(this.id), "messageId" in options
options, ? Routes.THREAD_START_PUBLIC(this.id, options.messageId)
: Routes.THREAD_START_PRIVATE(this.id),
{
name: options.name,
auto_archive_duration: options.autoArchiveDuration,
},
); );
return new ThreadChannel(this.session, thread, this.guildId); return new ThreadChannel(this.session, thread, thread.guild_id ?? this.guildId);
} }
} }