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––––––––––^^^^^^^^
相关文章