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 where to send its message, then why should it look for that channel in the cache? why should it get data it doesn’t need just to send a message? That’s where shorteners come in.

1
import { createEvent } from 'seyfert';
2
3
const db = new Map<string, string>();
4
5
export default createEvent({
6
data: { name: 'guildMemberAdd' },
7
run: async (member, client) => {
8
const channelId = db.get(member.guildId);
9
if (!channelId) { return; }
10
11
await client.messages.write(channelId, {
12
content: `Welcome ${member} :wave:`,
13
});
14
},
15
});

This applies to all seyfert, the methods in the classes that represent discord objects are just an extra layer of the shorteners for easy access, for example, by default seyfert does not add cache properties to the objects, but they bring facilities to access them.

1
import { createEvent } from 'seyfert';
2
3
const db = new Map<string, string>();
4
5
export default createEvent({
6
data: { name: 'guildMemberAdd' },
7
run: async (member, client) => {
8
const channelId = db.get(member.guildId);
9
if (!channelId) return;
10
11
// this is a fetch request to cache (force if you want direct api fetch)
12
const guild = await member.guild();
13
14
await client.messages.write(channelId, {
15
content: `Welcome ${member} to ${guild.name} :wave:`,
16
});
17
},
18
});

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:

1
import { createEvent } from 'seyfert';
2
3
export default createEvent({
4
data: { name: 'channelCreate' },
5
run: async (channel, client) => {
6
if (!channel.isThreadOnly()) return;
7
8
// assuming that channel.thread method does not exist
9
// the "object" will follow the same structure as the discord endpoints have
10
await client.proxy.channels(channel.id).threads.post({
11
body: {
12
name: 'First thread!',
13
message: {
14
content: 'Seyfert >',
15
},
16
},
17
reason: "I'm always the first",
18
});
19
},
20
});

Proxy has access to all types of the discord api, so it will always be a way to stay ahead even within the development versions.