如果在discord.py中有3分钟没有人加入频道,我如何让我的机器人离开vc?
这是我的离开命令atm的代码:如果在discord.py中有3分钟没有人加入频道,我如何让我的机器人离开vc?,discord,discord.py,Discord,Discord.py,这是我的离开命令atm的代码: @commands.command(name='leave',别名=['disconnect']) @commands.cooldown(1,2,commands.BucketType.user) @命令。具有权限(manage\u guild=True) 异步定义离开(self,ctx:commands.Context): 等待ctx.voice_state.stop() del self.voice_states[ctx.guild.id] 假设在vc中无人3
@commands.command(name='leave',别名=['disconnect'])
@commands.cooldown(1,2,commands.BucketType.user)
@命令。具有权限(manage\u guild=True)
异步定义离开(self,ctx:commands.Context):
等待ctx.voice_state.stop()
del self.voice_states[ctx.guild.id]
假设在vc中无人3分钟后,您正在寻找一个超时,请尝试将此作为起点:
导入异步IO
@commands.Cog.listener()
语音状态更新时的异步定义(自身、成员、之前、之后):
如果len(self.bot.get\u guild(id.voice\u client.channel.members)<1:
异步睡眠(180)
如果len(self.bot.get\u guild(id.voice\u client.channel.members)<1:
wait self.bot.get_guild(id).voice_client.disconnect()
ctx.voice\u client.disconnect()
将导致您断开连接并离开VC。没有这样的属性。voice\u state.stop()
从ctx
和删除self.voice\u states
将不起任何作用。我正在为我当前的音乐系统使用它,它可以完美地断开连接。哦,妈的,你说得对,我将修改我的答案以使用它,谢谢!好的,我试试这个!谢谢@Pr0methium啊,我刚刚注意到一个输入错误,你需要在第二个if语句后添加一个冒号,在async deflol之后,没问题,我已经试过了,甚至我注意到输入错误xD