所以我想向我的机器人添加一个错误报告命令,这是我的代码:
@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}>')
我希望只有作者和具有特定角色的人才能查看BugChannel
答案 0 :(得分:0)
您可以使用权限字典创建文本频道。
您可以在 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)
所以字典的键是 Role 或 User,值是 PermissionOverwrite。
而且你也应该只使用 ctx.guild
的 ctx.message.guild
插入