How do I create a new private text channel and add 2 people to it?(如何创建一个新的私人文本频道并添加 2 个人?)
问题描述
我正在创建一个不和谐的机器人,用户将在其中向机器人发送消息并
I'm creating a discord bot where a user will message the bot and
- 机器人将创建一个新的 PRIVATE 文本频道;最好与机器人在同一台服务器上
- 机器人只会将消息传递用户和管理员添加到频道
我已经能够使用 这个问题作为指导.我无法创建私人文本频道或找到允许我这样做的命令.有谁知道如何在 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 个人?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:如何创建一个新的私人文本频道并添加 2 个人?
基础教程推荐
- numpy float:比算术运算中内置的慢 10 倍? 2022-01-01
- 在 Celery 工作人员中捕获 Heroku SIGTERM 以优雅地关 2022-01-01
- 由Python将MP3转换为MIDI(类型错误:无法加载插件:mtg-Melodia:Melodia) 2022-01-01
- 将 x 轴刻度更改为自定义字符串 2022-01-01
- 尝试制作WhatsApp机器人 2022-01-01
- pyserial - 可以从线程 a 写入串行端口,是否阻塞从线程 b 读取? 2022-01-01
- Discord.py 缺少必需的参数 2022-01-01
- 用 Python 编写 Fortran 无格式文件 2022-01-01
- 使用生成器和迭代器时 Python 多循环失败 2022-01-01
- 与常规 dict 相比,Python manager.dict() 非常慢 2022-01-01
