如何创建权限覆盖以使 discord.py 中的用户静音?
How can I create permission overrides to mute a user in discord.py?
我不想使用静音角色,而是希望能够创建权限覆盖来更改服务器中每个频道中用户的权限,使其无法说任何话。但是,我不知道该怎么做,所以有人知道创建权限覆盖的方法,以便我可以使用我的 discord.py 机器人将用户静音吗?
以上是 NotSoBot 使用户静音的示例,我该如何复制它?
您可以明确拒绝分配给 user/role 的发送消息权限。这仅在发送消息权限在其他角色中被明确接受时才有效。我目前使用的代码会检查您是否有规则 __muted__
,如果有则删除您的消息:
@client.event
async def on_message(message):
if message.guild:
if '__muted__' in [role.name for role in message.author.roles]:
try:
await message.delete()
await message.author.send(f'\u274c You are muted in **{message.guild.name}**!')
return
except discord.errors.Forbidden:
pass
我不想使用静音角色,而是希望能够创建权限覆盖来更改服务器中每个频道中用户的权限,使其无法说任何话。但是,我不知道该怎么做,所以有人知道创建权限覆盖的方法,以便我可以使用我的 discord.py 机器人将用户静音吗?
以上是 NotSoBot 使用户静音的示例,我该如何复制它?
您可以明确拒绝分配给 user/role 的发送消息权限。这仅在发送消息权限在其他角色中被明确接受时才有效。我目前使用的代码会检查您是否有规则 __muted__
,如果有则删除您的消息:
@client.event
async def on_message(message):
if message.guild:
if '__muted__' in [role.name for role in message.author.roles]:
try:
await message.delete()
await message.author.send(f'\u274c You are muted in **{message.guild.name}**!')
return
except discord.errors.Forbidden:
pass