如何创建一个新的私人文本频道并添加 2 个人? [英] How do I create a new private text channel and add 2 people to it?

查看:15
本文介绍了如何创建一个新的私人文本频道并添加 2 个人?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在创建一个不和谐的机器人,用户将在其中向机器人发送消息并

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

  1. 机器人将创建一个新的 PRIVATE 文本频道;最好与机器人在同一台服务器上
  2. 机器人只会将消息传递用户和管理员添加到频道

我已经能够使用 这个问题作为指导.我无法创建私人文本频道或找到允许我这样做的命令.有谁知道如何在 discord.py 中创建一个私人文本频道并向其中添加 2 个人(消息用户和管理员)?

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?

推荐答案

你可以使用 Guild.create_text_channel 创建具有某些权限覆盖的文本频道.下面创建了一个频道,该频道仅对调用者、机器人和具有管理员"权限的成员可见.角色(您需要将其更改为适合您服务器的角色)

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),
        member: discord.PermissionOverwrite(read_messages=True),
        admin_role: discord.PermissionOverwrite(read_messages=True)
    }
    channel = await guild.create_text_channel('secret', overwrites=overwrites)

这篇关于如何创建一个新的私人文本频道并添加 2 个人?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆