Python 不和谐主题歌曲[有点解决了]
我想给我的一些朋友的主题歌曲,我已经能够做到这一点,使用下面的代码Python 不和谐主题歌曲[有点解决了],python,ffmpeg,discord,voice,Python,Ffmpeg,Discord,Voice,我想给我的一些朋友的主题歌曲,我已经能够做到这一点,使用下面的代码 @commands.Cog.listener() async def on_voice_state_update(ctx, member, before, after): if member.name in theme_songs.keys(): voice = await member.voice.channel.connect() voice.play(
@commands.Cog.listener()
async def on_voice_state_update(ctx, member, before, after):
if member.name in theme_songs.keys():
voice = await member.voice.channel.connect()
voice.play(discord.FFmpegPCMAudio(source=f"theme_songs/{theme_songs[member.name]}"))
问题是,每次有事情发生时,即静音、上线等,机器人都会被激活。
我怎样才能让它只寻找会员加入
编辑
我找到了解决这个问题的一种方法,添加
if before.channel != after.channel:
它变成
@commands.Cog.listener()
async def on_voice_state_update(self, member, before, after):
if before.channel != after.channel:
if member.name in theme_songs.keys():
voice = await after.channel.connect()
voice.play(discord.FFmpegPCMAudio(source=f"theme_songs/{theme_songs[member.name]}"))
这不是一个完美的解决方案,但它目前仍然有效尝试添加另一个
(如果
)来检查他们是否加入了频道
@commands.Cog.listener()
语音状态更新时的异步定义(ctx、成员、之前、之后):
如果before.channel为无:
如果主题中的member.name_songs.keys():
voice=wait member.voice.channel.connect()
voice.play(discord.ffmpegpcaudio(source=f“theme\u songs/{theme\u songs[member.name]}”))
如果,请尝试添加另一个,以检查他们是否加入频道
@commands.Cog.listener()
语音状态更新时的异步定义(ctx、成员、之前、之后):
如果before.channel为无:
如果主题中的member.name_songs.keys():
voice=wait member.voice.channel.connect()
voice.play(discord.ffmpegpcaudio(source=f“theme\u songs/{theme\u songs[member.name]}”))