問題描述
我正在創(chuàng)建一個不和諧的機器人,用戶將在其中向機器人發(fā)送消息并
I'm creating a discord bot where a user will message the bot and
- 機器人將創(chuàng)建一個新的 PRIVATE 文本頻道;最好與機器人在同一臺服務(wù)器上
- 機器人只會將消息傳遞用戶和管理員添加到頻道
我已經(jīng)能夠使用 這個問題作為指導(dǎo).我無法創(chuàng)建私人文本頻道或找到允許我這樣做的命令.有誰知道如何在 discord.py 中創(chuàng)建一個私人文本頻道并向其中添加 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
創(chuàng)建具有某些權(quán)限覆蓋的文本頻道.下面創(chuàng)建了一個頻道,該頻道僅對調(diào)用者、機器人和具有管理員"權(quán)限的成員可見.角色(您需要將其更改為適合您服務(wù)器的角色)
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)
這篇關(guān)于如何創(chuàng)建一個新的私人文本頻道并添加 2 個人?的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網(wǎng)!