mirror of
https://github.com/discordjs/discord.js.git
synced 2026-03-11 00:53:31 +01:00
feat: Add @discordjs/core (#8736)
* feat: add @discordjs/core * chore: lint * chore: add all gateway events * chore: add the rest of the rest routes * chore: cleanup gateway * chore: rename gateway to client * chore: rename gateway to client * fix: don't spread unless we need to * refactor: use classes and make requested changes * chore: show shardId on emit * chore: add interface for intrinsic props * refactor: scope dispatch data instead of spreading * chore: add utility for uploading files for messages and interactions * feat: finish up form data handling * chore: add readme * chore: update api-extractor stuff * chore: bump deps * chore: make requested changes * chore: make requested changes * Update package.json * chore: make requested changes * fix: add missing interaction responses * chore: make some requested changes * chore: remove `return await` * chore: use autoModeration instead of automod * refactor: use snowflakes and -types results * chore: sort imports, fix return type on editUserVoiceState * chore: rename bots to users * feat: add automod dispatch events * refactor: move templates and members into guild * fix: use users instead of bots in api class * chore: imports * chore: make requested changes * fix: don't make files required on interaction replies * fix: rename sendMessage to createMessage * feat: add application command routes * feat: add webhook.execute overloads and options to invites.get * chore: use create prefixes * chore: seperate interaction params * chore: use Id * chore: make requested changes * chore: make requested changes * chore: make requested changes * chore: for -> from * Apply suggestions from code review Co-authored-by: Jiralite <33201955+Jiralite@users.noreply.github.com> * Update packages/core/README.md Co-authored-by: Jiralite <33201955+Jiralite@users.noreply.github.com> * chore: make requested changes * chore: update -types * chore: bump vitest * fix: sticker uploading * fix: lockfile * chore: make requested changes * chore: make requested changes * Update packages/core/src/api/applicationCommands.ts Co-authored-by: Almeida <almeidx@pm.me> * Apply suggestions from code review Co-authored-by: Aura Román <kyradiscord@gmail.com> * Update packages/core/README.md Co-authored-by: Jiralite <33201955+Jiralite@users.noreply.github.com> * Apply suggestions from code review Co-authored-by: Jiralite <33201955+Jiralite@users.noreply.github.com> Co-authored-by: almeidx <almeidx@pm.me> Co-authored-by: Jiralite <33201955+Jiralite@users.noreply.github.com> Co-authored-by: Aura Román <kyradiscord@gmail.com> Co-authored-by: kodiakhq[bot] <49736102+kodiakhq[bot]@users.noreply.github.com>
This commit is contained in:
117
packages/core/src/api/thread.ts
Normal file
117
packages/core/src/api/thread.ts
Normal file
@@ -0,0 +1,117 @@
|
||||
import type { RawFile, REST } from '@discordjs/rest';
|
||||
import {
|
||||
Routes,
|
||||
type APIThreadChannel,
|
||||
type APIThreadMember,
|
||||
type RESTGetAPIChannelThreadMembersResult,
|
||||
type RESTPostAPIChannelThreadsJSONBody,
|
||||
type RESTPostAPIChannelThreadsResult,
|
||||
type RESTPostAPIGuildForumThreadsJSONBody,
|
||||
type Snowflake,
|
||||
} from 'discord-api-types/v10';
|
||||
|
||||
export interface StartThreadOptions extends RESTPostAPIChannelThreadsJSONBody {
|
||||
message_id?: string;
|
||||
}
|
||||
|
||||
export interface StartForumThreadOptions extends RESTPostAPIGuildForumThreadsJSONBody {
|
||||
message: RESTPostAPIGuildForumThreadsJSONBody['message'] & { files?: RawFile[] };
|
||||
}
|
||||
|
||||
export class ThreadsAPI {
|
||||
public constructor(private readonly rest: REST) {}
|
||||
|
||||
/**
|
||||
* Fetches a thread
|
||||
*
|
||||
* @param channelId - The id of the channel to fetch the thread from
|
||||
* @param threadId - The id of the thread
|
||||
*/
|
||||
public async get(channelId: Snowflake, threadId: Snowflake) {
|
||||
return this.rest.get(Routes.threads(channelId, threadId)) as Promise<APIThreadChannel>;
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates a new thread
|
||||
*
|
||||
* @param channelId - The id of the channel to start the thread in
|
||||
* @param data - The data to use when starting the thread
|
||||
*/
|
||||
public async create(channelId: Snowflake, { message_id, ...body }: StartThreadOptions) {
|
||||
return this.rest.post(Routes.threads(channelId, message_id), { body }) as Promise<RESTPostAPIChannelThreadsResult>;
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates a new forum post
|
||||
*
|
||||
* @param channelId - The id of the forum channel to start the thread in
|
||||
* @param data - The data to use when starting the thread
|
||||
*/
|
||||
public async createForumThread(channelId: Snowflake, { message, ...optionsBody }: StartForumThreadOptions) {
|
||||
const { files, ...messageBody } = message;
|
||||
|
||||
const body = {
|
||||
...optionsBody,
|
||||
message: messageBody,
|
||||
};
|
||||
|
||||
return this.rest.post(Routes.threads(channelId), { files, body }) as Promise<APIThreadChannel>;
|
||||
}
|
||||
|
||||
/**
|
||||
* Adds the current user to a thread
|
||||
*
|
||||
* @param threadId - The id of the thread to join
|
||||
*/
|
||||
public async join(threadId: Snowflake) {
|
||||
await this.rest.put(Routes.threadMembers(threadId, '@me'));
|
||||
}
|
||||
|
||||
/**
|
||||
* Adds a member to a thread
|
||||
*
|
||||
* @param threadId - The id of the thread to add the member to
|
||||
* @param userId - The id of the user to add to the thread
|
||||
*/
|
||||
public async addMember(threadId: Snowflake, userId: Snowflake) {
|
||||
await this.rest.put(Routes.threadMembers(threadId, userId));
|
||||
}
|
||||
|
||||
/**
|
||||
* Removes the current user from a thread
|
||||
*
|
||||
* @param threadId - The id of the thread to leave
|
||||
*/
|
||||
public async leave(threadId: Snowflake) {
|
||||
await this.rest.delete(Routes.threadMembers(threadId, '@me'));
|
||||
}
|
||||
|
||||
/**
|
||||
* Removes a member from a thread
|
||||
*
|
||||
* @param threadId - The id of the thread to remove the member from
|
||||
* @param userId - The id of the user to remove from the thread
|
||||
*/
|
||||
public async removeMember(threadId: Snowflake, userId: Snowflake) {
|
||||
await this.rest.delete(Routes.threadMembers(threadId, userId));
|
||||
}
|
||||
|
||||
/**
|
||||
* Fetches a member of a thread
|
||||
*
|
||||
* @param threadId - The id of the thread to fetch the member from
|
||||
* @param userId - The id of the user
|
||||
*/
|
||||
public async getMember(threadId: Snowflake, userId: Snowflake) {
|
||||
return this.rest.get(Routes.threadMembers(threadId, userId)) as Promise<APIThreadMember>;
|
||||
}
|
||||
|
||||
/**
|
||||
* Fetches all members of a thread
|
||||
*
|
||||
* @param threadId - The id of the thread to fetch the members from
|
||||
*/
|
||||
public async getAllMembers(threadId: Snowflake) {
|
||||
return this.rest.get(Routes.threadMembers(threadId)) as Promise<RESTGetAPIChannelThreadMembersResult>;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user