我如何覆盖“@everyone”频道中的单个权限
How do i overwrite a single permission in a channel for '@everyone'
这是我的代码。它将所有其他权限设置为默认值并将发送消息更改为 false。
@client.command()
@commands.has_permissions(manage_channels=True)
async def lock(ctx):
await ctx.channel.set_permissions(ctx.guild.default_role, send_messages=False)
await ctx.send('Channel locked.')
@lock.error
async def lock_error(ctx, error):
if isinstance(error,commands.CheckFailure):
await ctx.send('You do not have permission to use this command!')
如果我对你的评论理解正确,这段代码应该保持所有其他权限不变,并且只将你明确告诉它的权限更改为:
@client.command()
@commands.has_permissions(manage_channels=True)
async def lock(ctx):
overwrite = ctx.channel.overwrites_for(ctx.guild.default_role)
overwrite.send_messages = False
await ctx.channel.set_permissions(ctx.guild.default_role, overwrite=overwrite)
await ctx.send('Channel locked.')
@lock.error
async def lock_error(ctx, error):
if isinstance(error,commands.CheckFailure):
await ctx.send('You do not have permission to use this command!')
参考文献:
这是我的代码。它将所有其他权限设置为默认值并将发送消息更改为 false。
@client.command()
@commands.has_permissions(manage_channels=True)
async def lock(ctx):
await ctx.channel.set_permissions(ctx.guild.default_role, send_messages=False)
await ctx.send('Channel locked.')
@lock.error
async def lock_error(ctx, error):
if isinstance(error,commands.CheckFailure):
await ctx.send('You do not have permission to use this command!')
如果我对你的评论理解正确,这段代码应该保持所有其他权限不变,并且只将你明确告诉它的权限更改为:
@client.command()
@commands.has_permissions(manage_channels=True)
async def lock(ctx):
overwrite = ctx.channel.overwrites_for(ctx.guild.default_role)
overwrite.send_messages = False
await ctx.channel.set_permissions(ctx.guild.default_role, overwrite=overwrite)
await ctx.send('Channel locked.')
@lock.error
async def lock_error(ctx, error):
if isinstance(error,commands.CheckFailure):
await ctx.send('You do not have permission to use this command!')
参考文献: