Python - 将频道添加到类别

Python - Adding channel to category(Python - 将频道添加到类别)
本文介绍了Python - 将频道添加到类别的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

问题描述

限时送ChatGPT账号..

我正在尝试创建一个将在类别中创建的频道,但我尝试过的事情没有奏效

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 - 将频道添加到类别的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

本站部分内容来源互联网,如果有图片或者内容侵犯了您的权益,请联系我们,我们会在确认后第一时间进行删除!

相关文档推荐

groupby multiple coords along a single dimension in xarray(在xarray中按单个维度的多个坐标分组)
Group by and Sum in Pandas without losing columns(Pandas中的GROUP BY AND SUM不丢失列)
Group by + New Column + Grab value former row based on conditionals(GROUP BY+新列+基于条件的前一行抓取值)
Groupby and interpolate in Pandas(PANDA中的Groupby算法和插值算法)
Pandas - Group Rows based on a column and replace NaN with non-null values(PANAS-基于列对行进行分组,并将NaN替换为非空值)
Grouping pandas DataFrame by 10 minute intervals(按10分钟间隔对 pandas 数据帧进行分组)