python-3.x - 断开特定用户与频道的连接
问题描述
我正在制作一个discord.py 机器人,并试图断开特定用户与 voiceChannel 的连接。我在文档中看到了方法voice_client
,discord.guild
我试图让所有的voice_clients连接到公会的voice_channels。为了稍后搜索特定的voice_client并使用voice_clients.disconnect()方法断开它。但是没有guild.voice_client
返回,也许有更好的方法来做到这一点,或者我错过了什么?
这是我的一部分代码
async def vc(ctx):
for guild in bot.guilds:
if guild.id == myguild:
print(guild.voice_client) #return none
for vClients in guild.voice_client: #raise error (none is non-iterable)
await ctx.send("thing")
解决方案
async def kick(ctx: commands.Context, user: discord.Member):
await ctx.send(f'{user.mention} has been kicked from {user.voice.channel.mention}')
await user.move_to(None)
推荐阅读
- javascript - 如何使用 JavaScript 获取 AJAX 的选择值
- facebook - Facebook 消息 Webhook 事件:如何识别消息是页面故事的回复/评论?
- java - 如何在jsonobject中存储图像
- flutter - SharedPreferences.getInstance() 总是返回 null
- android - Android按钮文本对齐不起作用
- r - 如何从一组 N 个对象中选择 n 个对象,最大化它们之间的成对距离之和
- postgresql - 如何安装和启动 PostgreSQL 作为独立的基于 Python 的应用程序的一部分?
- python - Pandas:如何找到列的分箱均值
- bash - 从文件中获取特定字符串
- docker - 如何在 kubectl set 映像上指定注册表凭据?