maincategory = discord.utils.get(guild.categories, id=858441350667698190)
所以这是正常的方法,但我想通过提供变量来实现:
wanted_category_id = 858441350667698190
maincategory = discord.utils.get(guild.categories, id=wanted_category_id)
但是当我 print(maincategory)
时它说 None
我该怎么做?
答案 0 :(得分:0)
category = bot.get_channel(wanted_category_id)
brand_new_channel = await category.create_text_channel( # There's also create_voice_channel and create_stage_channel.
channel_name, # channel_name should be "general", not "#general".
# The rest are optional.
overwrites={ # Used for custom channel permissions and private channels.
guild.default_role: discord.PermissionOverwrite(
send_messages=False # By default, members can't send messages...
),
guild.me: discord.PermissionOverwrite.from_pair(
discord.Permissions.all(), # But the bot has all permissions enabled...
discord.Permissions.none() # And none disabled!
)
},
reason='Because I can' # This shows up in the audit logs.
)
await brand_new_channel.send('Ooh boy! A shiny new channel!')
重要部分:
await category.create_text_channel(channel_name)