问题描述
我希望创建一个命令,该命令可以使用discord.py修改特定文本通道的权限。例如,禁用在特定频道中发送消息。
I would have liked to make a command that allows to modify the permissions of a particular text channel discord with discord.py. For example, disable sending messages in a specific channel.
我查看了discord.py的文档,发现其中存在一个PermissionOverwrite类()允许在权限级别上执行某些操作(特别是使用功能更新)
I looked at the documentation of discord.py and I saw that there is a PermissionOverwrite class (https://discordpy.readthedocs.io/en/latest/api.html?highlight=app#permissionoverwrite) allowing to do some things at the level of the permissions (notably with the function update)
@client.command()
async def perm(ctx):
perms = discord.Permissions()
ctx.channel.perms.update(send_messages=False)
命令引发了一个异常:AttributeError:'TextChannel'对象没有属性'perms'
Command raised an exception: AttributeError: 'TextChannel' object has no attribute 'perms'
推荐答案
使用:
@client.command()
async def perm(ctx):
await ctx.channel.set_permissions(ctx.guild.default_role, send_messages=False)
这篇关于使用discord.py更改不和谐文本通道的权限的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!