Recipes

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 {  } from 'seyfert';
 
const  = new <string, string>();
 
export default ({
	: { : 'guildMemberAdd' },
	: async (, ) => {
		const  = .(.);
		if (!) { return; }
 
		await ..(, {
			: `Welcome ${} :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 {  } from 'seyfert';
 
const  = new <string, string>();
 
export default ({
	: { : 'guildMemberAdd' },
	: async (, ) => {
		const  = .(.);
		if (!) return;
 
		// this is a fetch request to cache (force it if you want a direct api fetch)
		const  = await .();
 
		await ..(, {
			: `Welcome ${} to ${.} :wave:`,
		});
	},
});
 

Proxy

About Proxy section

This section talks specifically about the implementation of the Proxy object, not about the integration of a proxy in the rest.

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 {  } from 'seyfert';
 
export default ({
	: { : 'channelCreate' },
	: async (, ) => {
		if (!.()) return; 
 
		// assuming that channel.thread method does not exist
		// the "object" will follow the same structure as the discord endpoints have
		await ..(.)..({
			: {
				: 'First thread!',
				: {
					: 'Seyfert >',
				},
			},
			: "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.

On this page