【发布时间】: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