How do I create a new private text channel and add 2 people to it?

一笑奈何 提交于 2020-01-06 05:54:24

问题


I'm creating a discord bot where a user will message the bot and

  1. the bot will create a new PRIVATE text channel; preferably on the same server as the bot
  2. the bot will add only the messaging user and an admin to the channel

I have been able to make a new channel using this question as a guide. I have not been able to make a private text channel or find a command that will allow me to do so. Does anyone know how to create a private text channel in discord.py and add 2 people (messaging user and an admin) to it?


回答1:


You can use Guild.create_text_channel to create a text channel with certain permissions overwrites. The below creates a channel that is visible only to the caller, the bot, and members with the "Admin" role (You'll need to change that to the appropriate role for your server)

from discord.utils import get

@bot.command()
async def make_channel(ctx):
    guild = ctx.guild
    member = ctx.author
    admin_role = get(guild.roles, name="Admin")
    overwrites = {
        guild.default_role: discord.PermissionOverwrite(read_messages=False),
        guild.me: discord.PermissionOverwrite(read_messages=True),
        admin_role: discord.PermissionOverwrite(read_messages=True)
    }
    channel = await guild.create_text_channel('secret', overwrites=overwrites)


来源:https://stackoverflow.com/questions/56241314/how-do-i-create-a-new-private-text-channel-and-add-2-people-to-it

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!