Skip to content

Commit

Permalink
Change command disconnect
Browse files Browse the repository at this point in the history
Update the disconnect command so that it doesn't say disconnected when it doesn't have an active player in the guild. Additionally adds i18n support.

Update cmd-restart-invalid-arg i18n to match with what's in the code.
  • Loading branch information
BabyBoySnow committed Jan 11, 2024
1 parent 01773d4 commit 7694da0
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 4 deletions.
4 changes: 3 additions & 1 deletion config/i18n/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -140,12 +140,14 @@
"cmd-move-indexes-not-intergers": "Song indexes must be integers.",
"cmd-move-invalid-indexes": "Sent indexes are outside of playlist scope!",
"cmd-move-success": "Successfully moved the requested song from position number {} in queue to position {}!",
"cmd-restart-invalid-arg": "Invalid option given, use soft or full.",
"cmd-restart-invalid-arg": "Invalid option given, use: soft, full, upgrade, uppip, or upgit.",
"cmd-restart-soft": "{emoji} Restarting current instance...",
"cmd-restart-full": "{emoji} Restarting bot process...",
"cmd-restart-uppip": "{emoji} Will try to upgrade required pip packages and restart the bot...",
"cmd-restart-upgit": "{emoji} Will try to update bot code with git and restart the bot...",
"cmd-restart-upgrade": "{emoji} Will try to upgrade everything and restart the bot...",
"cmd-disconnect-success": "Disconnected from `{0.name}",
"cmd-disconnect-no-voice": "Not currently connected to `{0.name}`",
"playlists-noperms": "You are not allowed to request playlists",
"playlists-big": "Playlist has too many entries ({0} > {1})",
"playlists-limit": "Playlist entries + your already queued songs reached limit ({0} + {1} > {2})",
Expand Down
20 changes: 17 additions & 3 deletions musicbot/bot.py
Original file line number Diff line number Diff line change
Expand Up @@ -4525,8 +4525,22 @@ async def cmd_disconnect(self, guild):
Forces the bot leave the current voice channel.
"""
await self.disconnect_voice_client(guild)
return Response("Disconnected from `{0.name}`".format(guild), delete_after=20)
voice_client = self.get_player_in(guild)
if voice_client:
await self.disconnect_voice_client(guild)
return Response(
self.str.get(
"cmd-disconnect-success", "Disconnected from `{0.name}`"
).format(guild),
delete_after=20,
)
else:
raise exceptions.CommandError(
self.str.get(
"cmd-disconnect-no-voice", "Not currently connected to `{0.name}`"
).format(guild),
expire_in=30,
)

async def cmd_restart(self, _player, channel, leftover_args, opt="soft"):
"""
Expand All @@ -4545,7 +4559,7 @@ async def cmd_restart(self, _player, channel, leftover_args, opt="soft"):
raise exceptions.CommandError(
self.str.get(
"cmd-restart-invalid-arg",
"Invalid option given, use: soft, full, upgrade, uppip, or upgit",
"Invalid option given, use: soft, full, upgrade, uppip, or upgit.",
),
expire_in=30,
)
Expand Down

0 comments on commit 7694da0

Please sign in to comment.