【问题标题】:Discord Py - Is there anyways to add members to a private channel through discord py without the use of roles?Discord Py - 是否可以通过不使用角色的不和谐 py 将成员添加到私人频道?
【发布时间】:2021-08-14 03:40:47
【问题描述】:

有没有办法通过 discord py 将成员添加到私人频道而不使用角色。我知道您可以通过为用户提供允许用户访问频道的特定角色集来使用角色将用户添加到私人频道。但是,如果我允许大量用户创建他们自己的特定私人频道并为他们分配自己的特定角色,那么服务器角色将充满垃圾邮件角色。我确实想到了一个定时角色移除器,它可以跟踪该频道中的用户活动,但这将依赖于超级主机端,因为这会带来许多在主机和服务器之间发送的不必要的包。

我还尝试创建邀请链接,该链接将在创建频道后通过 dms 发送给用户,但问题是我设置了默认角色无权查看该频道的权限,因此又回到了开头,因为它需要角色才能查看频道。 代码如下:

category_name = "Pets_Private_Channels"
await ctx.send("Setting up management!")
category = discord.utils.get(ctx.guild.categories, name=category_name)
user = ctx.author.id
overwrites = {
    ctx.guild.default_role: discord.PermissionOverwrite(read_messages=False), #Make default not able to view this private channel
    ctx.guild.me: discord.PermissionOverwrite(read_messages=True), #Add the bot to the channel
}


if category is None: #If there's no category matching with the `name`
    category = await ctx.guild.create_category(category_name, overwrites=None, reason=None)
    channel = await ctx.guild.create_text_channel(user, overwrites=overwrites, reason=None, category=category)
    invitelink = await channel.create_invite(max_uses=1,unique=True)
    print(channel)
    await ctx.author.send(invitelink)

else: #Else if it found the categoty
    #await ctx.guild.create_text_channel(user, overwrites=overwrites, reason=None, category=category)
    channel = await ctx.guild.create_text_channel(user, overwrites=overwrites, reason=None, category=category)
    invitelink = await channel.create_invite(max_uses=1,unique=True)
    print(channel)
    await ctx.author.send(invitelink)

所以我只是想知道是否有办法将用户添加到频道而不给他们所需的特定角色。就像私人频道你可以“添加成员或角色”我们可以添加一个成员。

如果有人能提供帮助,我们将不胜感激。提前致谢。

此代码块已解决问题。

overwrites = {
         ctx.guild.default_role: discord.PermissionOverwrite(read_messages=False),
         ctx.guild.me: discord.PermissionOverwrite(read_messages=True),
         ctx.author: discord.PermissionOverwrite(read_messages=True)}

【问题讨论】:

    标签: python discord.py


    【解决方案1】:

    可以在覆盖中专门选择成员。它们必须是 discord.Member 对象。

    overwrites = {
                 ctx.guild.default_role: discord.PermissionOverwrite(read_messages=False),
                 ctx.guild.me: discord.PermissionOverwrite(read_messages=True),
                 ctx.author: discord.PermissionOverwrite(read_messages=True), 
    }
    

    您可以添加任意数量的discord.Member 对象并放置您需要的内容。

    【讨论】:

    • 哦,等等……我昨天确实尝试了 ctx.author,但它显示了与属性相关的错误……哦,哇,我知道今天发生了什么,但非常感谢!谢谢!
    • 我想可能是因为你使用了ctx.author.id。我只是根据您使用的user 变量进行假设。
    • Ohh nonono 我一开始确实使用了它,但后来将其更改为 ctx.author 然后最后删除了它,因为属性问题不断出现......我不知道@.@但是现在它可以工作了。再次非常感谢!很大的帮助谢谢你我被困在这个问题上很可笑的时间。
    猜你喜欢
    • 2021-05-15
    • 2018-08-11
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-05-31
    • 2019-11-05
    • 2021-11-15
    • 1970-01-01
    相关资源
    最近更新 更多