python discord bot临时语音通道

时间:2020-09-15 15:18:56

标签: python python-3.x discord discord.py

仅当我静音,断音或开始/停止流媒体播放时,语音频道才会出现。当我加入“➕KanalErstellen➕”频道时,如何解决此问题?如何立即进入临时频道?

    async def on_voice_state_update(self, member, before, after):
        if member.bot:
            return

        if not before.channel:
            print(f'{member.name} joined {after.channel.name}')

        if before.channel and not after.channel:
            print(f'{member.name} left {before.channel.name}')

        if before.channel and after.channel:
            if before.channel.id != after.channel.id:
                print(f'{member.name} switched from {before.channel.name} to {after.channel.name}')
            else:
                if member.voice.self_stream:
                    print(f'{member.name} started streaming')
                    self.current_streamers.append(member.id)
                elif member.voice.self_mute:
                    print(f'{member.name} muted')
                else:
                    for streamer in self.current_streamers:
                        if member.id == streamer:
                            if not member.voice.self_stream:
                                print(f'{member.name} stopped streaming')
                                self.current_streamers.remove(member.id)
                            break

                if after.channel is not None:
                    if after.channel.name == "➕Kanal Erstellen➕":
                        channel = await creat_voice_channel(after.channel.guild, f'{member.name}´s Callcenter'.lower(),
                                                            category_name="Temp")

                        if channel is not None:
                            await member.move_to(channel)

                if before.channel is not None:
                    if before.channel.category.id == get_category_by_name(before.channel.guild, "Temp").id:
                        print("User left Temp channel")
                        if len(before.channel.members) == 0:
                            print("channel empty")
                            await before.channel.delete()```

1 个答案:

答案 0 :(得分:0)

我相信您的问题是if before.channel and after.channel:,当您最初加入频道时,不会出现before.channel,因为您之前没有进入频道,并且您的代码也没有要运行。