Python - Adding channel to category(Python - 将频道添加到类别)
本文介绍了Python - 将频道添加到类别的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在尝试创建一个将在类别中创建的频道,但我尝试过的事情没有奏效
I'm trying to create a channel that'll be created in a category but the things I've tried haven't worked
代码很大,所以我不会显示所有内容,只是添加频道
The code is pretty big so I won't be showing everything, just down to adding the channel
@client.command()
@has_permissions(kick_members=True)
async def warn(ctx, member:discord.Member, *, reason=None):
arg=reason
author=ctx.author
guild=ctx.message.guild
overwritee = discord.PermissionOverwrite()
overwrite = discord.PermissionOverwrite()
channel = get(guild.text_channels, name='warn-logs')
category = get(guild.category_channels, name='Multi-Logs')
mrole = get(ctx.guild.roles, name="Multi-Galaxy")
if category is None:
category = await guild.create_category_channel("Multi-Logs")
overwritee.read_messages = False
overwritee.read_message_history = False
overwritee.send_messages = False
overwrite.read_messages = True
overwrite.read_message_history = True
overwrite.send_messages = True
await channel.set_permissions(guild.default_role, overwrite=overwritee)
await channel.set_permissions(mrole, overwrite=overwrite)
if channel is None:
channel = await guild.create_text_channel('warn-logs')
overwritee.read_messages = False
overwritee.read_message_history = False
overwritee.send_messages = False
overwrite.read_messages = True
overwrite.read_message_history = True
overwrite.send_messages = True
await channel.set_permissions(guild.default_role, overwrite=overwritee)
await channel.set_permissions(mrole, overwrite=overwrite)
它只是创建类别 &频道彼此分开,因此频道不在类别中
It just creates the category & the channel apart from each other, so the channel isn't in the category
推荐答案
只需在 category.html#discord.Guild.create_text_channel" rel="nofollow noreferrer">create_text_channel
:
Simply pass in a category
in create_text_channel
:
if channel is None:
channel = await guild.create_text_channel('warn-logs', category=category)
# ^^^^^^^^^^^^^^^^^
# keyword-argument––––^^^^^^^^
# your-variable––––––––––^^^^^^^^
这篇关于Python - 将频道添加到类别的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
沃梦达教程
本文标题为:Python - 将频道添加到类别
猜你喜欢
- 使用 Cython 将 Python 链接到共享库 2022-01-01
- YouTube API v3 返回截断的观看记录 2022-01-01
- 我如何卸载 PyTorch? 2022-01-01
- 计算测试数量的Python单元测试 2022-01-01
- 检查具有纬度和经度的地理点是否在 shapefile 中 2022-01-01
- 如何使用PYSPARK从Spark获得批次行 2022-01-01
- 使用公司代理使Python3.x Slack(松弛客户端) 2022-01-01
- ";find_element_by_name(';name';)";和&QOOT;FIND_ELEMENT(BY NAME,';NAME';)";之间有什么区别? 2022-01-01
- 我如何透明地重定向一个Python导入? 2022-01-01
- CTR 中的 AES 如何用于 Python 和 PyCrypto? 2022-01-01