1+ using Discord . WebSocket ;
2+ using DiscordLab . Bot . API . Enums ;
3+
4+ namespace DiscordLab . Bot . API . Extensions
5+ {
6+ public static class ClientExtensions
7+ {
8+ public static GuildReturn TryGetGuild ( this DiscordSocketClient client , ulong guildId , out SocketGuild guild )
9+ {
10+ if ( guildId == 0 )
11+ {
12+ guild = null ;
13+ return GuildReturn . NoGuild ;
14+ }
15+ SocketGuild tempGuild = client . GetGuild ( guildId ) ;
16+ if ( tempGuild == null )
17+ {
18+ guild = null ;
19+ return GuildReturn . InvalidGuild ;
20+ }
21+ guild = tempGuild ;
22+ return GuildReturn . Found ;
23+ }
24+
25+ public static ChannelReturn TryGetTextChannel ( this DiscordSocketClient client , ulong channelId , out SocketTextChannel channel )
26+ {
27+ if ( channelId == 0 )
28+ {
29+ channel = null ;
30+ return ChannelReturn . NoChannel ;
31+ }
32+ SocketChannel tempChannel = client . GetChannel ( channelId ) ;
33+ if ( tempChannel == null )
34+ {
35+ channel = null ;
36+ return ChannelReturn . InvalidChannel ;
37+ }
38+ if ( tempChannel is not SocketTextChannel textChannel )
39+ {
40+ channel = null ;
41+ return ChannelReturn . InvalidType ;
42+ }
43+ channel = textChannel ;
44+ return ChannelReturn . Found ;
45+ }
46+
47+ public static ChannelReturn TryGetTextChannel ( this SocketGuild guild , ulong channelId ,
48+ out SocketTextChannel channel )
49+ {
50+ if ( channelId == 0 )
51+ {
52+ channel = null ;
53+ return ChannelReturn . NoChannel ;
54+ }
55+ SocketTextChannel tempChannel = guild . GetTextChannel ( channelId ) ;
56+ if ( tempChannel == null )
57+ {
58+ channel = null ;
59+ return ChannelReturn . InvalidChannel ;
60+ }
61+ channel = tempChannel ;
62+ return ChannelReturn . Found ;
63+ }
64+ }
65+ }
0 commit comments