Description
Summary
The channel.connect() never ends. The bot appears in the channel on Discord, but the code "thinks" he isn't connected.
Reproduction Steps
- Launch my bot
- Go in the proper voice channel
- Execute the /play command (see the code)
Minimal Reproducible Code
class Blindtest(commands.Cog):
def __init__(self, bot):
self.bot = bot
self.musiques = []
def cog_check(interaction):
member = interaction.guild.get_member(interaction.user.id)
salon_blindtest = interaction.guild.get_channel(CHANNEL_ID)
return member.voice != None and member.voice.channel == salon_blindtest and interaction.channel == salon_blindtest
@app_commands.command(description = "Permet de jouer un morceau de musique")
@app_commands.check(cog_check)
async def play(self, interaction: discord.Interaction):
member = interaction.guild.get_member(interaction.user.id)
url = 'SOME URL'
client = interaction.guild.voice_client
if client and client.channel and client.is_connected():
self.musiques.append(url)
else:
channel = member.voice.channel
self.musiques = []
print(1)
client = await channel.connect()
print(2)
self.play_song(client, self.musiques, url)
await interaction.response.send_message(':notes: Je lance la lecture !')
class MyBot(commands.Bot):
def __init__(self):
super().__init__(command_prefix = "!", intents = intents, description = "Tapez !aide")
#self.tree = app_commands.CommandTree(self)
async def setup_hook(self):
pass
bot = MyBot()
@bot.event
async def on_ready():
await bot.wait_until_ready()
print('Connecté en tant que', bot.user
await bot.load_extension(NAME_OF_THE_FILE)
bot.tree.copy_global_to(guild = MY_GUILD)
await bot.tree.sync(guild = MY_GUILD)
print('Prêt !')
bot.run(MY_TOKEN)
Expected Results
The bot should connect to the vocal channel, send a message, and then start playing a file via the function play_song
.
It should too print "1" and then "2" in the console.
Actual Results
I get the "1" in the console, but never the "2".
The bot appears connected to the channel on Discord. However, the code below channel.connect()
is never executed.
I made some experiments, and I can see that when I ask for is_connected(), the answer is False.
Intents
intents = discord.Intents.all()
System Information
- Python v3.9.2-final
- discord.py v2.3.2-final
- aiohttp v3.8.4
- system info: Linux 6.1.34-v8+ # 1657 SMP PREEMPT Fri Jun 16 12:36:29 BST 2023
Checklist
- I have searched the open issues for duplicates.
- I have shown the entire traceback, if possible.
- I have removed my token from display, if visible.
Additional Context
I wrote this code in March 2023 and it worked perfectly. Then I tried it again in July, without any modification, and it wasn't working anymore. It still is broken.
I saw that I'm not the only one with this problem, but I also saw that many people do not have this problem. I suspected a firewall blocking so I disabled it and nothing changed. Still, I am not convinced because I don't know which port is used for the voice channel connection. If anyone knows that, I can try to specifically allow it in my firewall.
I put here only the part of the code which is concerned by the problem. The COG is in a separate python file. I think I put all code needed to understand the problem. Let me know if something is missing.