Shorters and Proxy
Shorters
Shorters are a simple combination of the seyfert methods and the discord api, in seyfert they are intended for easy user access to the methods of all discord objects without having to instantiate their representative class or if it does not exist. Saving a lot of resources in unnecessary data accesses.
Suppose we have a welcome system, in its database, it already has access to the id of the channel whereto send its message, then why should it look for that channel in the cache? why should it get data? doesn’t it need to simply send a message? That’s where shorters come in.
This applies to all seyfert, the methods in the classes that represent discord objects are just an extra layer of the shorters for easy access, for example, by default seyfert does not add cache properties to the objects, but brings amenities to access them.
import { function createEvent<E extends ClientNameEvents | CustomEventsKeys>(data: { data: { name: E; once?: boolean; }; run: (...args: ResolveEventParams<E>) => any;}): { data: { name: E; once?: boolean; }; run: (...args: ResolveEventParams<E>) => any;}
Creates an event with the specified data and run function.
createEvent } from 'seyfert';
const const db: Map<string, string>
db = new var Map: MapConstructornew <string, string>(iterable?: Iterable<readonly [string, string]> | null | undefined) => Map<string, string> (+3 overloads)
Map<string, string>();
export default createEvent<"guildMemberAdd">(data: { data: { name: "guildMemberAdd"; once?: boolean; }; run: (args_0: GuildMember, args_1: UsingClient, args_2: number) => any;}): { ...;}
Creates an event with the specified data and run function.
createEvent({ data: { name: "guildMemberAdd"; once?: boolean;}
data: { name: "guildMemberAdd"
name: 'guildMemberAdd' }, run: (args_0: GuildMember, args_1: UsingClient, args_2: number) => any
run: async (member: GuildMember
member, client: UsingClient
client) => { const const channelId: string | undefined
channelId = const db: Map<string, string>
db.Map<string, string>.get(key: string): string | undefined
Returns a specified element from the Map object. If the value that is associated to the provided key is an object, then you will get a reference to that object and any change made to that object will effectively modify it inside the Map.
get(member: GuildMember
member.GuildMember.guildId: string
the choosen guild id
guildId); if (!const channelId: string | undefined
channelId) return;
// this is a fetch request to cache (force it if you want a direct api fetch) const const guild: Guild<"api">
guild = await member: GuildMember
member.BaseGuildMember.guild(force?: boolean): Promise<GuildStructure<"api">>
guild();
await client: UsingClient
client.BaseClient.messages: MessageShorter
messages.MessageShorter.write(channelId: string, { files, ...body }: MessageCreateBodyRequest): Promise<MessageStructure>
write(const channelId: string
channelId, { content?: string | undefined
The message contents (up to 2000 characters)
content: `Welcome ${member: GuildMember
member} to ${const guild: Guild<"api">
guild.name: string
name} :wave:`, }); },});
Proxy
The proxy object is the layer below the shorters, it is in charge of creating a path with the code relying on the autocompletion of typescript, it is basically the api of discord made an incredibly fast object.
Is there anything that is not supported in seyfert? Then access it directly, let’s create a thread directly with the discord api:
import { function createEvent<E extends ClientNameEvents | CustomEventsKeys>(data: { data: { name: E; once?: boolean; }; run: (...args: ResolveEventParams<E>) => any;}): { data: { name: E; once?: boolean; }; run: (...args: ResolveEventParams<E>) => any;}
Creates an event with the specified data and run function.
createEvent } from 'seyfert';
export default createEvent<"channelCreate">(data: { data: { name: "channelCreate"; once?: boolean; }; run: (args_0: AllChannels, args_1: UsingClient, args_2: number) => any;}): { data: { ...; }; run: (args_0: AllChannels, args_1: UsingClient, args_2: number) => any;}
Creates an event with the specified data and run function.
createEvent({ data: { name: "channelCreate"; once?: boolean;}
data: { name: "channelCreate"
name: 'channelCreate' }, run: (args_0: AllChannels, args_1: UsingClient, args_2: number) => any
run: async (channel: AllChannels
channel, client: UsingClient
client) => { if (!channel: AllChannels
channel.BaseNoEditableChannel<T extends ChannelType>.isThreadOnly(): this is ForumChannel | MediaChannel
isThreadOnly()) return;
// assuming that channel.thread method does not exist // the "object" will follow the same structure as the discord endpoints have await client: UsingClient
client.BaseClient.proxy: APIRoutes
proxy.ChannelRoutes.channels(id: string): { get(args?: RestArgumentsNoBody): Promise<RESTGetAPIChannelResult>; patch(args: RestArguments<RESTPatchAPIChannelJSONBody>): Promise<RESTPatchAPIChannelResult>; delete(args?: RestArgumentsNoBody): Promise<RESTDeleteAPIChannelResult>; users: (id: "@me") => { threads: { archived: { private: { get(args?: RestArgumentsNoBody<RESTGetAPIChannelThreadsArchivedQuery>): Promise<RESTGetAPIChannelUsersThreadsArchivedResult>; }; }; }; }; "thread-members": { get(args?: RestArgumentsNoBody<RESTGetAPIChannelThreadMembersQuery>): Promise<RESTGetAPIChannelThreadMembersResult>; (id: "@me"): { put(args?: RestArgumentsNoBody): Promise<RESTPutAPIChannelThreadMembersResult>; delete(args?: RestArgumentsNoBody): Promise<RESTDeleteAPIChannelThreadMembersResult>; }; (id: string): { get(args?: RestArgumentsNoBody<RESTGetAPIChannelThreadMemberQuery>): Promise<RESTGetAPIChannelThreadMemberResult>; put(args?: RestArgumentsNoBody): Promise<RESTPutAPIChannelThreadMembersResult>; delete(args?: RestArgumentsNoBody): Promise<RESTDeleteAPIChannelThreadMembersResult>; }; }; threads: { post(args: RestArguments<RESTPostAPIChannelThreadsJSONBody | RESTPostAPIGuildForumThreadsJSONBody>): Promise<RESTPostAPIChannelThreadsResult>; archived: { public: { get(args?: RestArgumentsNoBody<RESTGetAPIChannelThreadsArchivedQuery>): Promise<RESTGetAPIChannelThreadsArchivedPublicResult ...
channels(channel: MediaChannel | ForumChannel
channel.DiscordBase<Data extends Record<string, any> = { id: string; }>.id: string
id).threads: { post(args: RestArguments<RESTPostAPIChannelThreadsJSONBody | RESTPostAPIGuildForumThreadsJSONBody>): Promise<RESTPostAPIChannelThreadsResult>; archived: { public: { get(args?: RestArgumentsNoBody<RESTGetAPIChannelThreadsArchivedQuery>): Promise<RESTGetAPIChannelThreadsArchivedPublicResult>; }; private: { get(args?: RestArgumentsNoBody<RESTGetAPIChannelThreadsArchivedQuery>): Promise<RESTGetAPIChannelThreadsArchivedPrivateResult>; }; };}
threads.function post(args: RestArguments<RESTPostAPIChannelThreadsJSONBody | RESTPostAPIGuildForumThreadsJSONBody>): Promise<RESTPostAPIChannelThreadsResult>
post({ body: RESTPostAPIChannelThreadsJSONBody | RESTPostAPIGuildForumThreadsJSONBody
body: { RESTPostAPIChannelMessagesThreadsJSONBody.name: string
1-100 character thread name
name: 'First thread!', message: RESTPostAPIChannelMessageJSONBody
The initial message of the thread
message: { RESTPostAPIChannelMessageJSONBody.content?: string | undefined
The message contents (up to 2000 characters)
content: 'Seyfert >', }, }, reason?: string
reason: "I'm always the first", }); },});
Proxy has access to all types of the discord api, so it’ll be always a way to stay ahead even within the development versions.