/[sudobot]/branches/2.x/src/api/Validator.ts
ViewVC logotype

Contents of /branches/2.x/src/api/Validator.ts

Parent Directory Parent Directory | Revision Log Revision Log


Revision 577 - (show annotations)
Mon Jul 29 18:52:37 2024 UTC (8 months ago) by rakinar2
File MIME type: application/typescript
File size: 1559 byte(s)
chore: add old version archive branches (2.x to 9.x-dev)
1 import { Guild, GuildChannel, GuildMember, Role, TextChannel, User } from "discord.js";
2 import DiscordClient from "../client/Client";
3
4 export async function isChannel(id: string | number, guild: string): Promise <boolean> {
5 try {
6 const channel = <GuildChannel> await (<Guild> await DiscordClient.client.guilds.fetch(guild)).channels.fetch(id.toString());
7
8 if (!channel || (channel.type !== 'GUILD_TEXT' && channel.type !== 'GUILD_NEWS' && channel.type !== 'GUILD_CATEGORY'))
9 return false;
10 }
11 catch (e) {
12 return false;
13 }
14
15 return true;
16 }
17
18 export async function isRole(id: string | number, guild: string): Promise <boolean> {
19 try {
20 const role = <Role> await (<Guild> await DiscordClient.client.guilds.fetch(guild)).roles.fetch(id.toString());
21
22
23 if (!role)
24 return false;
25 }
26 catch (e) {
27 return false;
28 }
29
30 return true;
31 }
32
33 export async function isMember(id: string | number, guild: string): Promise <boolean> {
34 try {
35 const member = <GuildMember> await (<Guild> await DiscordClient.client.guilds.fetch(guild)).members.fetch(id.toString());
36
37 if (!member)
38 return false;
39 }
40 catch (e) {
41 return false;
42 }
43
44 return true;
45 }
46
47 export async function isUser(id: string | number): Promise <boolean> {
48 try {
49 const user = <User> await DiscordClient.client.users.fetch(id.toString());
50
51 if (!user)
52 return false;
53 }
54 catch (e) {
55 return false;
56 }
57
58 return true;
59 }

team@onesoftnet.eu.org
ViewVC Help
Powered by ViewVC 1.1.26