Skip to content

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.

import { createEvent } from 'seyfert';
const db = new Map<string, string>();
export default createEvent({
data: { name: 'guildMemberAdd' },
run: async (member, client) => {
const channelId = db.get(member.guildId);
if (!channelId) { return; }
await client.messages.write(channelId, {
content: `Welcome ${member} :wave:`,
});
},
});

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 { createEvent } from 'seyfert';
const db = new Map<string, string>();
export default createEvent({
data: { name: 'guildMemberAdd' },
run: async (member, client) => {
const channelId = db.get(member.guildId);
if (!channelId) return;
// this is a fetch request to cache (force it if you want a direct api fetch)
const guild = await member.guild();
await client.messages.write(channelId, {
content: `Welcome ${member} to ${guild.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 { createEvent } from 'seyfert';
export default createEvent({
data: { name: 'channelCreate' },
run: async (channel, client) => {
if (!channel.isThreadOnly()) return;
// assuming that channel.thread method does not exist
// the "object" will follow the same structure as the discord endpoints have
await client.proxy.channels(channel.id).threads.post({
body: {
name: 'First thread!',
message: {
content: 'Seyfert >',
},
},
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.