我正在创建一个不和谐的机器人,用户将在其中向机器人发送消息并
I'm creating a discord bot where a user will message the bot and
我已经能够使用 这个问题作为指导.我无法创建私人文本频道或找到允许我这样做的命令.有谁知道如何在 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 个人?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!