设置已创建通道Discord.PY的权限

2024-10-01 02:40:35 发布

您现在位置:Python中文网/ 问答频道 /正文

因此,我想向我的bot添加一个bug报告命令,这是我的代码:

@client.command()
async def bug(ctx):
    guild = ctx.message.guild
    BugChannel = await guild.create_text_channel(f'bugreport {ctx.author.name}')
    await ctx.send(f'{ctx.author.mention} Describe your Bug in <#{BugChannel.id}>')

我希望只有作者和具有特定角色的ppl才能查看BugChannel


Tags: 代码命令clientmessageasyncdefbot报告
1条回答
网友
1楼 · 发布于 2024-10-01 02:40:35

您可以创建具有权限的文本频道。
你可以在Docs中阅读更多关于它的信息

举个例子,它是:

overwrites = {
    guild.default_role: discord.PermissionOverwrite(view_channel=False),
    ctx.author: discord.PermissionOverwrite(view_channel=True),
    your_role: discord.PermissionOverwrite(view_channel=True)
}
channel = await ctx.guild.create_text_channel(f'bugreport {ctx.author.name}', overwrites=overwrites)

所以dict的键是aRole或aUser和值aPermissionOverwrite

您还应该只使用ctx.guildinsetad of ctx.message.guild

相关问题 更多 >