本文介绍了您如何使用权限覆盖?Discord.py 重写的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我一直在尝试为我的不和谐机器人创建静音命令和票证命令,但我无法解决权限覆盖问题.提前谢谢你
I have been trying to make a mute command and a ticket command for my discord bot but i can't wrap my head around permission overwrites. Thank you in advance
推荐答案
这是一个用于在服务器范围内(即机器人可以看到的每个文本通道)编辑特定成员权限的命令:
Here's a command for editing a certain member's permissions server-wide (i.e. for each text channel the bot can see):
import discord # if you get an error about discord not being defined, include this at the top
@bot.command()
async def mute(ctx, member: discord.Member):
for channel in ctx.guild.text_channels:
perms = channel.overwrites_for(member)
perms.send_messages = False
await channel.set_permissions(member, overwrite=perms, reason="Muted!")
await ctx.send(f"{member} has been muted.")
参考资料:
TextChannel.overwrites_for()
- 请记住,这可以包含角色或用户/成员对象.TextChannel.set_permissions()
Guild.text_channels
这篇关于您如何使用权限覆盖?Discord.py 重写的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!