问题描述
我正在创建一个不和谐的机器人,用户将在其中向机器人发送消息并
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 个人?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!


大气响应式网络建站服务公司织梦模板
高端大气html5设计公司网站源码
织梦dede网页模板下载素材销售下载站平台(带会员中心带筛选)
财税代理公司注册代理记账网站织梦模板(带手机端)
成人高考自考在职研究生教育机构网站源码(带手机端)
高端HTML5响应式企业集团通用类网站织梦模板(自适应手机端)