add getchannel

This commit is contained in:
Skillz
2020-08-25 10:51:49 -04:00
parent 5c4e7c47e9
commit 3479c7d549
2 changed files with 31 additions and 5 deletions
+1 -1
View File
@@ -2,7 +2,7 @@ name: Discordeno
description: >- description: >-
Discord Deno TypeScript API library wrapper(Officially vetted library by Discord Deno TypeScript API library wrapper(Officially vetted library by
Discord Team) https://discordeno.netlify.app Discord Team) https://discordeno.netlify.app
version: 8.1.0 version: 8.2.0
stable: true stable: true
files: files:
- ./src/**/* - ./src/**/*
+30 -4
View File
@@ -139,8 +139,30 @@ export function deleteChannel(
* *
* ⚠️ **If you need this, you are probably doing something wrong. This is not intended for use. Your channels will be cached in your guild.** * ⚠️ **If you need this, you are probably doing something wrong. This is not intended for use. Your channels will be cached in your guild.**
*/ */
export function getChannels(guildID: string) { export async function getChannels(guildID: string, addToCache = true) {
return RequestManager.get(endpoints.GUILD_CHANNELS(guildID)); const result = await RequestManager.get(
endpoints.GUILD_CHANNELS(guildID),
) as ChannelCreatePayload[];
return result.map((res) => {
const channel = createChannel(res, guildID);
if (addToCache) {
cache.channels.set(channel.id, channel);
}
return channel;
});
}
/** Fetches a single channel object from the api.
*
* ⚠️ **If you need this, you are probably doing something wrong. This is not intended for use. Your channels will be cached in your guild.**
*/
export async function getChannel(channelID: string, addToCache = true) {
const result = await RequestManager.get(
endpoints.GUILD_CHANNEL(channelID),
) as ChannelCreatePayload;
const channel = createChannel(result, result.guild_id);
if (addToCache) cache.channels.set(channel.id, channel);
return channel;
} }
/** Modify the positions of channels on the guild. Requires MANAGE_CHANNELS permisison. */ /** Modify the positions of channels on the guild. Requires MANAGE_CHANNELS permisison. */
@@ -178,13 +200,17 @@ export async function getMember(guildID: string, id: string) {
* *
* ⚠️ **ADVANCED USE ONLY: Your members will be cached in your guild most likely. Only use this when you are absolutely sure the member is not cached.** * ⚠️ **ADVANCED USE ONLY: Your members will be cached in your guild most likely. Only use this when you are absolutely sure the member is not cached.**
*/ */
export async function getMembersByQuery(guildID: string, name: string, limit = 1) { export async function getMembersByQuery(
guildID: string,
name: string,
limit = 1,
) {
const guild = cache.guilds.get(guildID); const guild = cache.guilds.get(guildID);
if (!guild) return; if (!guild) return;
return new Promise((resolve) => { return new Promise((resolve) => {
requestAllMembers(guild, resolve, { query: name, limit }); requestAllMembers(guild, resolve, { query: name, limit });
}) });
} }
/** Create an emoji in the server. Emojis and animated emojis have a maximum file size of 256kb. Attempting to upload an emoji larger than this limit will fail and return 400 Bad Request and an error message, but not a JSON status code. If a URL is provided to the image parameter, Discordeno will automatically convert it to a base64 string internally. */ /** Create an emoji in the server. Emojis and animated emojis have a maximum file size of 256kb. Attempting to upload an emoji larger than this limit will fail and return 400 Bad Request and an error message, but not a JSON status code. If a URL is provided to the image parameter, Discordeno will automatically convert it to a base64 string internally. */