I'm creating a discord bot where a user will message the bot and
- the bot will create a new PRIVATE text channel; preferably on the same server as the bot
- 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?
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)