Skip to content

Commit 0fe4310

Browse files
AAA3A-AAA3ADrapersniperJackenmenKreusada
authored
Allow passing a voice channel to [p]summon (#5536)
Co-authored-by: Draper <27962761+Drapersniper@users.noreply.github.com> Co-authored-by: Jakub Kuczys <me@jacken.men> Co-authored-by: Kreusada <67752638+Kreusada@users.noreply.github.com>
1 parent 28ff1f6 commit 0fe4310

2 files changed

Lines changed: 30 additions & 12 deletions

File tree

docs/cog_guides/audio.rst

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3199,12 +3199,15 @@ summon
31993199

32003200
.. code-block:: none
32013201
3202-
[p]summon
3202+
[p]summon [voice_channel]
32033203
32043204
**Description**
32053205

32063206
Summon the bot to a voice channel.
32073207

3208+
If ``[voice_channel]`` is not specified, the bot will join the channel you are currently in.
3209+
``[voice_channel]`` can be a channel link ("Copy Link" option in channel's context menu) or ID.
3210+
32083211
.. _audio-command-volume:
32093212

32103213
^^^^^^

redbot/cogs/audio/core/commands/controller.py

Lines changed: 26 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -618,8 +618,14 @@ async def command_stop(self, ctx: commands.Context):
618618
@commands.guild_only()
619619
@commands.cooldown(1, 15, commands.BucketType.guild)
620620
@commands.bot_has_permissions(embed_links=True)
621-
async def command_summon(self, ctx: commands.Context):
622-
"""Summon the bot to a voice channel."""
621+
async def command_summon(
622+
self, ctx: commands.Context, *, voice_channel: discord.VoiceChannel = None
623+
):
624+
"""Summon the bot to a voice channel.
625+
626+
If `[voice_channel]` is not specified, the bot will join the channel you are currently in.
627+
`[voice_channel]` can be a channel link ("Copy Link" option in channel's context menu) or ID.
628+
"""
623629
dj_enabled = self._dj_status_cache.setdefault(
624630
ctx.guild.id, await self.config.guild(ctx.guild).dj_enabled()
625631
)
@@ -643,10 +649,22 @@ async def command_summon(self, ctx: commands.Context):
643649
)
644650

645651
try:
652+
if voice_channel is not None:
653+
current_perms = voice_channel.permissions_for(ctx.author)
654+
if not current_perms.connect:
655+
ctx.command.reset_cooldown(ctx)
656+
return await self.send_embed_msg(
657+
ctx,
658+
title=_("Unable To Join Voice Channel"),
659+
description=_(
660+
"You don't have permission to connect to the specified channel."
661+
),
662+
)
663+
channel = voice_channel or ctx.author.voice.channel
646664
if (
647-
not self.can_join_and_speak(ctx.author.voice.channel)
648-
or not ctx.author.voice.channel.permissions_for(ctx.me).move_members
649-
and self.is_vc_full(ctx.author.voice.channel)
665+
not self.can_join_and_speak(channel)
666+
or not channel.permissions_for(ctx.me).move_members
667+
and self.is_vc_full(channel)
650668
):
651669
ctx.command.reset_cooldown(ctx)
652670
return await self.send_embed_msg(
@@ -656,25 +674,22 @@ async def command_summon(self, ctx: commands.Context):
656674
)
657675
if not self._player_check(ctx):
658676
player = await lavalink.connect(
659-
ctx.author.voice.channel,
677+
channel,
660678
self_deaf=await self.config.guild_from_id(ctx.guild.id).auto_deafen(),
661679
)
662680
player.store("notify_channel", ctx.channel.id)
663681
else:
664682
player = lavalink.get_player(ctx.guild.id)
665683
player.store("notify_channel", ctx.channel.id)
666-
if (
667-
ctx.author.voice.channel == player.channel
668-
and ctx.guild.me in ctx.author.voice.channel.members
669-
):
684+
if channel == player.channel and ctx.guild.me in channel.members:
670685
ctx.command.reset_cooldown(ctx)
671686
return await self.send_embed_msg(
672687
ctx,
673688
title=_("Unable To Do This Action"),
674689
description=_("I am already in your channel."),
675690
)
676691
await player.move_to(
677-
ctx.author.voice.channel,
692+
channel,
678693
self_deaf=await self.config.guild_from_id(ctx.guild.id).auto_deafen(),
679694
)
680695
await ctx.tick()

0 commit comments

Comments
 (0)