Skip to content
This repository was archived by the owner on Feb 3, 2025. It is now read-only.
Open
Show file tree
Hide file tree
Changes from 5 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
61 changes: 61 additions & 0 deletions rest/Endpoints.ts
Original file line number Diff line number Diff line change
Expand Up @@ -363,6 +363,67 @@ export default class Endpoints {
return `/guilds/${guildID}/templates/${code}`;
}

// Threads
/**
* `/channels/:channelID/messages/:messageID/threads`
* - POST - Creates a new thread from an existing message
*/
public static START_THREAD_WITH_MESSAGE(channelID: string, messageID: string) {
return `/channels/${channelID}/messages/${messageID}/threads`;
}
/**
* `/channels/:channelID/threads`
* - POST - Creates a new thread that is not connected to an existing message
*/
public static START_THREAD_WITHOUT_MESSAGE(channelID: string) {
return `/channels/${channelID}/threads`;
}
/**
* `/channels/:channelID/thread-members/@me`
* - PUT - Adds the current user to a thread
* - DELETE - Removes the current user from a thread
*/
public static THREAD(channelID: string) {
return `/channels/${channelID}/thread-members/@me`;
}
/**
* `/channels/:channelID/thread-members/:userID`
* - PUT - Adds another member to a thread
* - DELETE - Removes another member from a thread
*/
public static THREAD_MEMBER(channelID: string, userID: string) {
return `/channels/${channelID}/thread-members/${userID}`;
}
/**
* `/channels/:channelID/thread-members`
* - GET - Returns array of thread members objects that are members of the thread
*/
public static LIST_THREAD_MEMBERS(channelID: string) {
return `/channels/${channelID}/thread-members`;
}
/**
* `/channels/:channelID/threads/active`
* - GET - Returns all active threads in the channel, including public and private threads
*/
public static LIST_ACTIVE_THREADS(channelID: string) {
return `/channels/${channelID}/threads/active`;
}
/**
* `/channels/:channelID}/threads/archived/public OR private`
* - GET & type = public - Returns archived threads in the channel that are public
* - GET & type = private - Returns archived threads in the channel that are of type GUILD_PRIVATE_THREAD
*/
public static LIST_ARCHIVED_THREADS(channelID: string, type: 'public' | 'private') {
return `/channels/${channelID}/threads/archived/${type}`;
}
/**
* `/channels/:channelID/users/@me/threads/archived/private`
* - GET - Returns archived threads in the channel that are of type GUILD_PRIVATE_THREAD, and the user has joined
*/
public static LIST_JOINED_PRIVATE_ARCHIVED_THREADS(channelID: string) {
return `/channels/${channelID}/users/@me/threads/archived/private`;
}

// User
/**
* `/users/:userID`
Expand Down
2 changes: 1 addition & 1 deletion rest/RESTClient.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import { REST_CONSTANTS } from '../src/util/Constants';
const { version, repository } = require('../../package.json');

export default class RESTClient {
version = 'v8';
version = 'v9';
apiURL = `/api/${this.version}`;// eslint-disable-line @typescript-eslint/member-ordering
readonly client: Client;
globallyRateLimited = false;
Expand Down
52 changes: 52 additions & 0 deletions src/Client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,10 @@ export default class Client {
return this.rest.request('PUT', Endpoints.CHANNEL_PINNED_MESSAGE(channelID, messageID), true);
}

addThreadMember(channelID: string, userID: string) {
return this.rest.request('PUT', Endpoints.THREAD_MEMBER(channelID, userID), true);
}

beginGuildPrune(guildID: string, params: any = {}) {
return this.rest.request('POST', Endpoints.GUILD_PRUNE(guildID), true, {
days: params.days,
Expand Down Expand Up @@ -499,10 +503,40 @@ export default class Client {
: this.rest.request('GET', Endpoints.WEBHOOK(webhookID), true);
}

joinThread(channelID: string) {
return this.rest.request('PUT', Endpoints.THREAD(channelID), true);
}

leaveGuild(guildID: string) {
return this.rest.request('DELETE', Endpoints.USER_GUILD(guildID), true);
}

leaveThread(channelID: string) {
return this.rest.request('DELETE', Endpoints.THREAD(channelID), true);
}

listActiveThreads(channelID: string) {
return this.rest.request('GET', Endpoints.LIST_ACTIVE_THREADS(channelID), true);
}

listArchivedThreads(channelID: string, type: 'public'|'private', params: any = {}) {
return this.rest.request('GET', Endpoints.LIST_ARCHIVED_THREADS(channelID, type), true, {
before: params.before,
limit: params.limit,
});
}

listJoinedPrivateArchivedThreads(channelID: string, params: any = {}) {
return this.rest.request('GET', Endpoints.LIST_JOINED_PRIVATE_ARCHIVED_THREADS(channelID), true, {
before: params.before,
limit: params.limit,
});
}

listThreadMembers(channelID: string) {
return this.rest.request('GET', Endpoints.LIST_THREAD_MEMBERS(channelID), true);
}

listVoiceRegions() {
return this.rest.request('GET', Endpoints.VOICE_REGIONS(), true);
}
Expand All @@ -526,6 +560,24 @@ export default class Client {
return this.rest.request('DELETE', Endpoints.GUILD_MEMBER_ROLE(guildID, userID, roleID), true);
}

removeThreadMember(channelID: string, userID: string) {
return this.rest.request('DELETE', Endpoints.THREAD_MEMBER(channelID, userID), true);
}

startThreadWithMessage(channelID: string, messageID: string, params: any = {}) {
return this.rest.request('POST', Endpoints.START_THREAD_WITH_MESSAGE(channelID, messageID), true, {
name: params.name,
auto_archive_duration: params.autoArchiveDuration,
});
}

startThreadWithoutMessage(channelID: string, params: any = {}) {
return this.rest.request('POST', Endpoints.START_THREAD_WITHOUT_MESSAGE(channelID), true, {
name: params.name,
auto_archive_duration: params.autoArchiveDuration,
});
}

syncGuildIntegration(guildID: string, integrationID: string) {
return this.rest.request('POST', Endpoints.GUILD_INTEGRATION_SYNC(guildID, integrationID), true);
}
Expand Down
8 changes: 8 additions & 0 deletions src/util/Constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -401,6 +401,9 @@ export enum JSON_ERROR_CODES {
INVALID_CHANNEL_DELETE_COMMUNITY = 50074,
// UNKNOWN 50075-50080,
INVALID_STICKER_SENT = 50081,
INVALID_THREAD_OPERATION = 50083,
INVALID_THREAD_NOTIFICATION_SETTINGS,
INVALID_THREAD_TIMESTAMP,

MFA_ENABLED = 60001,
MFA_DISABLED,
Expand Down Expand Up @@ -498,6 +501,11 @@ export enum PERMISSION_FLAGS {
MANAGE_ROLES = 1 << 28,
MANAGE_WEBHOOKS = 1 << 29,
MANAGE_EMOJIS = 1 << 30,
USE_SLASH_COMMANDS = 1 << 31,
REQUEST_TO_SPEAK = 1 << 32,
MANAGE_THREADS = 1 << 34,
USE_PUBLIC_THREADS = 1 << 35,
USE_PRIVATE_THREADS = 1 << 36,
}

// List of all limits
Expand Down
1 change: 1 addition & 0 deletions structures/Guild.ts
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ export default interface Guild extends Base {
splash: string | null;
system_channel_flags: SystemChannelFlags;
system_channel_id: string | null;
threads?: Channel[];
unavailable?: boolean;
vanity_url_code: string | null;
verification_level: VerificationLevel;
Expand Down
6 changes: 6 additions & 0 deletions ws/constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,12 @@ export const EVENTS = {
MESSAGE_REACTION_REMOVE_EMOJI: 'messageReactionRemoveEmoji',
PRESENCE_UPDATE: 'presenceUpdate',
TYPING_START: 'typingStart',
THREAD_CREATE: 'threadCreate',
THREAD_UPDATE: 'threadUpdate',
THREAD_DELETE: 'threadDelete',
THREAD_LIST_SYNC: 'threadListSync',
THREAD_MEMBER_UPDATE: 'threadMemberUpdate',
THREAD_MEMBERS_UPDATE: 'threadMembersUpdate',
USER_UPDATE: 'userUpdate',
VOICE_STATE_UPDATE: 'voiceStateUpdate',
VOICE_SERVER_UPDATE: 'guildServerUpdate',
Expand Down