当机器人独自一人时不会离开语音频道
我有一个个人音乐机器人,可以为我和朋友播放音乐,我只有一个播放和离开命令,这两个命令都可以完美工作,但我想知道是否可以对机器人进行一点升级,让机器人在单独放置时自动离开语音通道。在阅读了一些文档之后,我想我明白了,但是我的这段代码根本不起作用,它几乎就像 python 由于某种原因忽略了它,所以我想我在这里遗漏了一些东西...... 所以我想知道我的代码是否有原因:
@client.event
async def on_voice_state_update(member):
voice_state = member.guild.voice_client
if len(voice_state.channel.members) == 1:
await voice_state.disconnect()
无法工作,我没有收到任何错误消息,而且实际上什么也没有发生。这里的一切都是应该的吗?
I have a personal music bot that plays music for me and friends, I only have a play and leave commands which both work perfectly, but I was wondering if a little upgrade to the bot automatically leaving voice channel when left in it alone was possible. After some reading in documentation, I thought I got it but this piece of my code simply doesn't work, it's almost like python is ignoring it for some reason so I guess I am missing something here...
so I was wondering if there is a reason why my code:
@client.event
async def on_voice_state_update(member):
voice_state = member.guild.voice_client
if len(voice_state.channel.members) == 1:
await voice_state.disconnect()
won't work, I don't get any error messages and literally nothing happens. Is it all as it should be here?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您缺少此事件的一些参数。只需添加
before
和after
就可以了。完整的事件可能是:
您可以在此处的文档中查看更多信息:
on_voice_state_update
You are missing some arguments for this event. Simply add
before
andafter
and you should be fine.The full event could be:
You can see more in the docs here:
on_voice_state_update