python - 退出频道时如何删除频道房间 discord.py
问题描述
@bot.event
async def on_voice_state_update(member, before, after):
if before.channel is None and after.channel is not None:
await member.guild.system_channel.send(
"{} into the voice room".format(member.nick)
)
channel = await member.guild.create_text_channel('123')
if before.channel is not None and after.channel is None:
await member.guild.system_channel.send(
"{} out of the voice room".format(member.nick)
)
channel = await member.guild.delete_text_channel('123')
当我进入语音通道时,机器人会创建一个文本通道,如果我离开语音通道,机器人应该删除文本通道
但是当我出去的时候,bot没有删除频道我该如何修复这个代码?
解决方案
.delete_text_channel() 无效,您必须改用 .delete()
channel = discord.utils.get(member.guild.channels, name="123")
# If channel doesn't exits or channel is not TextChannel
if type(channel) != discord.channel.TextChannel or channel is None:
print("No channel found!")
return
await channel.delete()
推荐阅读
- python - python烧瓶如何显示图像
- scala - 在 Scala 中,需要将可能为 null 的值与可能为“null”的搜索字符串进行比较
- entity - D8 如何在 field--entity-reference.html.twig 文件的词汇术语中检索自定义字段的值?
- .net - Windows 事件日志中引用的“框架版本”是什么?
- r - 为另一个变量的每个 id 创建一个等于最后一个非 NA 值的变量
- ms-word - 将页脚添加到具有包含空格的列标题的 flextable 对象
- matlab - 如何在Matlab中将递归转换为分支定界算法的迭代方式
- go - 在 GO 中获取传入的 TTL
- php - 为什么 Apache2 将 www.myurl.com/php 映射到这个目录?
- php - PHP使用目录字符串上传文件