11package vc .commands ;
22
3- import discord4j .common .util .Snowflake ;
43import discord4j .core .event .domain .interaction .ChatInputInteractionEvent ;
54import discord4j .core .object .command .ApplicationCommandInteractionOption ;
65import discord4j .core .object .command .ApplicationCommandInteractionOptionValue ;
@@ -28,25 +27,24 @@ public LiveFeedCommand(final LiveFeed liveFeed) {
2827
2928 @ Override
3029 public Mono <Message > handle (final ChatInputInteractionEvent event ) {
31- if (! validateUserPermissions ( event )) return error (event , "You must have permission: " + Permission . MANAGE_MESSAGES
32- + " to use this command" );
30+ if (event . getInteraction (). getGuildId (). isEmpty ()) return error (event , "This command can only be used inside a discord server" );
31+ if (! validateUserPermissions ( event )) return error ( event , "You must have permission: " + Permission . MANAGE_MESSAGES + " to use this command" );
3332 Optional <Boolean > enabledBoolean = event .getOption ("enabled" )
3433 .flatMap (ApplicationCommandInteractionOption ::getValue )
3534 .map (ApplicationCommandInteractionOptionValue ::asBoolean );
3635 Optional <Mono <Channel >> channelArg = event .getOption ("channel" )
3736 .flatMap (ApplicationCommandInteractionOption ::getValue )
3837 .map (ApplicationCommandInteractionOptionValue ::asChannel );
3938 if (enabledBoolean .isEmpty () && channelArg .isEmpty ()) return error (event , "At least 1 argument is required" );
40- Optional <Snowflake > guildId = event .getInteraction ().getGuildId ();
41- if (guildId .isEmpty ()) return error (event , "This command can only be used in a guild" );
39+ var guildId = event .getInteraction ().getGuildId ().get ().asString ();
4240 if (enabledBoolean .orElse (true ) && channelArg .isEmpty ()) return error (event , "Channel is required when enabling " + feedName ());
4341 if (enabledBoolean .orElse (true )) {
4442 try {
4543 final Channel channel = channelArg .get ().block ();
46- if (!testPermissions (guildId . get (). asString () , channel )) {
44+ if (!testPermissions (guildId , channel )) {
4745 return error (event , "Bot must have permissions to send messages in: " + channel .getMention ());
4846 }
49- liveFeed .enableFeed (guildId . get (). asString () , channel .getId ().asString ());
47+ liveFeed .enableFeed (guildId , channel .getId ().asString ());
5048 return event .createFollowup ()
5149 .withEmbeds (EmbedCreateSpec .builder ()
5250 .title (feedName () + " Enabled" )
@@ -58,7 +56,7 @@ public Mono<Message> handle(final ChatInputInteractionEvent event) {
5856 }
5957 } else {
6058 try {
61- liveFeed .disableFeed (guildId . get (). asString () );
59+ liveFeed .disableFeed (guildId );
6260 return event .createFollowup ()
6361 .withEmbeds (EmbedCreateSpec .builder ()
6462 .title (feedName () + " Disabled" )
0 commit comments