Python - 将频道添加到类别

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

上一篇:Discord python关于角色授予事件 下一篇:Discord money bot 将用户 ID 保存在 json 文件中.当 Bot 重新启动时,它会为每个人创建一个

相关文章