You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
@commands.Cog.listener()
async def on_voice_state_update(self, member, before, after):
if before.channel is None and after.channel:
cursor.execute(f"SELECT Login FROM Users WHERE ID = {member.id}")
login_sound = cursor.fetchone()[0]
cursor.execute(f"SELECT Filepath FROM Sounds WHERE Name = '{login_sound}'")
source = discord.PCMVolumeTransformer(discord.FFmpegPCMAudio(cursor.fetchone()[0]), volume=volumeSet)
vc = await after.channel.connect()
vc.play(source, after=lambda e: print(f"Player error {e}") if e else None)
So I want to play a sound based on certain user while they connect to a voice channel. Now this code works fine when bot isn't connected to a voice. Of course if bot is already connected to a voice and hasn't been disconnected, this will not works as it will raise a ClientException.
Now my question is, how do I make the bot play the sound in this event while already connected to a voice channel or maybe switch voice channels before playing. Can't really figure out myself how I can make use of move_to method or access previous VoiceClient.
reacted with thumbs up emoji reacted with thumbs down emoji reacted with laugh emoji reacted with hooray emoji reacted with confused emoji reacted with heart emoji reacted with rocket emoji reacted with eyes emoji
Uh oh!
There was an error while loading. Please reload this page.
-
Here's the snippet:
So I want to play a sound based on certain user while they connect to a voice channel. Now this code works fine when bot isn't connected to a voice. Of course if bot is already connected to a voice and hasn't been disconnected, this will not works as it will raise a ClientException.
Now my question is, how do I make the bot play the sound in this event while already connected to a voice channel or maybe switch voice channels before playing. Can't really figure out myself how I can make use of move_to method or access previous VoiceClient.
Beta Was this translation helpful? Give feedback.
All reactions