用户登录
用户注册

分享至

如何创建一个新的私人文本频道并添加 2 个人?

  • 作者: 星期曰我没空
  • 来源: 51数据库
  • 2023-02-10

问题描述

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

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 *****) 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 "*****" 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
    *****_role = get(guild.roles, name="*****")
    overwrites = {
        guild.default_role: discord.PermissionOverwrite(read_messages=False),
        member: discord.PermissionOverwrite(read_messages=True),
        *****_role: discord.PermissionOverwrite(read_messages=True)
    }
    channel = await guild.create_text_channel('secret', overwrites=overwrites)
软件
前端设计
程序设计
Java相关