1
+ use log:: error;
1
2
use serenity:: all:: {
2
3
CommandDataOption , CommandDataOptionValue , CommandOptionType , CreateCommandOption ,
3
4
} ;
@@ -9,7 +10,7 @@ use std::any::Any;
9
10
use tracing:: info;
10
11
use trackscape_discord_shared:: database:: BotMongoDb ;
11
12
12
- pub fn _register ( ) -> CreateCommand {
13
+ pub fn register ( ) -> CreateCommand {
13
14
CreateCommand :: new ( "set_leagues_channel" )
14
15
. description ( "Sets a channel to receive league broadcasts. This is off by default" )
15
16
. default_member_permissions ( Permissions :: MANAGE_GUILD )
@@ -32,10 +33,21 @@ pub async fn run(
32
33
let option = options. get ( 0 ) . expect ( "Expected Channel Id option" ) ;
33
34
34
35
if let CommandDataOptionValue :: Channel ( channel) = option. value {
35
- if channel. type_id ( ) != ChannelType :: Text . type_id ( ) {
36
+ let possible_actual_channel = channel. to_channel ( & ctx) . await ;
37
+ if possible_actual_channel. is_err ( ) {
38
+ error ! ( "Error getting channel: {:?}" , possible_actual_channel. err( ) ) ;
39
+ return Some ( "Error getting channel" . to_string ( ) ) ;
40
+ }
41
+ let guild_channel = possible_actual_channel
42
+ . expect ( "Expected channel" )
43
+ . guild ( )
44
+ . expect ( "Expected guild channel" ) ;
45
+
46
+ if guild_channel. kind != ChannelType :: Text {
47
+ error ! ( "Please select a text channel." ) ;
36
48
return Some ( "Please select a text channel." . to_string ( ) ) ;
37
49
}
38
- info ! ( "Channel: {:?}" , channel ) ;
50
+
39
51
let saved_guild_query = db. guilds . get_by_guild_id ( guild_id) . await ;
40
52
41
53
return match saved_guild_query {
0 commit comments