1- from discord import Interaction , app_commands
1+ from discord import ClientException , Interaction , VoiceChannel , app_commands
22from discord .ext .commands import Cog
33
44from bot .main import ActBot
55from bot .ui import EmbedX
6- from db .actor import Actor
76
87
98# ----------------------------------------------------------------------------------------------------
@@ -30,21 +29,24 @@ async def sync(self, interaction: Interaction, global_sync: bool = True):
3029 ephemeral = True ,
3130 )
3231
33- # @app_commands.guild_only()
34- # @app_commands.checks.has_permissions(administrator=True)
35- # @app_commands.command(description="Synchronize commands")
36- # async def update_actors(self, interaction: Interaction):
37- # if not interaction.guild:
38- # return
39- # await interaction.response.defer(ephemeral=True)
40- # db = self.bot.get_db(interaction.guild)
41- # actors = db.find(Actor)
42- # members = interaction.guild.members
43- # for member in members:
44- # for actor in actors:
45- # if actor.id == member.id:
46-
47- # if not actor:
48- # actor = self.bot.create_actor(member)
49- # db.save_all(actors)
50- # await interaction.followup.send(embed=EmbedX.success(title="", description=f"{len(members)}/{len(actors)} actors updated."))
32+ # ----------------------------------------------------------------------------------------------------
33+ # * Join
34+ # ----------------------------------------------------------------------------------------------------
35+ @app_commands .default_permissions (administrator = True )
36+ @app_commands .checks .has_permissions (administrator = True )
37+ @app_commands .command (description = "Add bot to a voice channel" )
38+ async def join (self , interaction : Interaction , channel : VoiceChannel ):
39+ try :
40+ await channel .connect ()
41+ await interaction .response .send_message (
42+ embed = EmbedX .info (f"Joined { channel .name } ." ), ephemeral = True
43+ )
44+ except ClientException :
45+ await interaction .response .send_message (
46+ embed = EmbedX .warning ("Already in a voice channel." ), ephemeral = True
47+ )
48+ except Exception as e :
49+ await interaction .response .send_message (
50+ embed = EmbedX .error (f"Could not join the voice channel: { e } " ),
51+ ephemeral = True ,
52+ )
0 commit comments