@@ -111,13 +111,45 @@ private boolean channelChecks(CommandContext ctx, AudioUtils audioUtils, String
111111 return true ;
112112 }
113113
114- private boolean isAbleToJoinChannel (CommandContext ctx ) {
115- if (isUserOrGuildPatron (ctx , false )) {
116- return ctx .getMember ().getVoiceState ().inAudioChannel () &&
117- !getLavalinkManager ().isConnected (ctx .getGuild ());
114+ private boolean canRunSlashCommand (SlashCommandInteractionEvent event , DunctebotGuild guild , AudioUtils audioUtils ) {
115+ if (!event .getMember ().getVoiceState ().inAudioChannel ()) {
116+ event .reply ("Please join a voice channel first" ).setEphemeral (true ).queue ();
117+ return false ;
118+ }
119+
120+ final LavalinkManager lavalinkManager = getLavalinkManager ();
121+
122+ if (!lavalinkManager .isConnected (guild )) {
123+ event .reply ("I'm not in a voice channel, use `/join` to make me join a channel" )
124+ .setEphemeral (true )
125+ .queue ();
126+
127+ return false ;
128+ }
129+
130+ final AudioChannelUnion connectedChannel = lavalinkManager .getConnectedChannel (guild );
131+
132+ if (connectedChannel != null && !connectedChannel .getMembers ().contains (event .getMember ())) {
133+ event .reply ("I'm sorry, but you have to be in the same channel as me to use any music related commands" )
134+ .setEphemeral (true )
135+ .queue ();
136+
137+ return false ;
118138 }
119139
120- return false ;
140+ audioUtils .getMusicManager (guild .getIdLong ()).setLatestChannelId (event .getChannel ().getIdLong ());
141+ return true ;
142+ }
143+
144+ private boolean isAbleToJoinChannel (CommandContext ctx ) {
145+ // if (isUserOrGuildPatron(ctx, false)) {
146+ // return ctx.getMember().getVoiceState().inAudioChannel() &&
147+ // !getLavalinkManager().isConnected(ctx.getGuild());
148+ // }
149+
150+ // return false
151+ return ctx .getMember ().getVoiceState ().inAudioChannel () &&
152+ !getLavalinkManager ().isConnected (ctx .getGuild ());
121153 }
122154
123155 protected static LavalinkManager getLavalinkManager () {
@@ -129,6 +161,21 @@ protected SubcommandData getSubData() {
129161 return new SubcommandData (getName (), getHelp (getName (), "/" ));
130162 }
131163
164+ public void handleSlashWithAutoJoin (@ Nonnull SlashCommandInteractionEvent event , DunctebotGuild guild , @ Nonnull Variables variables ) {
165+ if (this .mayAutoJoin ) {
166+ // TODO: this will cause issues with the event not working properly, need to find a way to resolve this
167+ ((MusicCommand ) variables .getCommandManager ()
168+ .getCommand ("join" ))
169+ .handleEvent (event , guild , variables );
170+ this .handleEvent (event , guild , variables );
171+ return ;
172+ }
173+
174+ if (this .justRunLmao || canRunSlashCommand (event , guild , variables .getAudioUtils ())) {
175+ this .handleEvent (event , guild , variables );
176+ }
177+ }
178+
132179 public abstract void handleEvent (@ Nonnull SlashCommandInteractionEvent event , DunctebotGuild guild , @ Nonnull Variables variables );
133180
134181 public static SlashCommandData getMusicCommandData (CommandManager mngr ) {
0 commit comments