我正在用discord.py构建一个机器人。我有一个静音命令,效果很好。但是,当我尝试禁用具有mod/admin权限和/或其角色高于bot的成员时,命令会运行,但用户不会被禁用。如果你能告诉我如何处理这件事,那会很有帮助。错误是:-
Traceback (most recent call last):
File "/Users/user/Desktop/ProgrammingAndCoding/TomAndJerry/.venv/lib/python3.9/site-packages/discord/client.py", line 343, in _run_event
await coro(*args, **kwargs)
File "/Users/user/Desktop/ProgrammingAndCoding/TomAndJerry/main.py", line 94, in on_command_error
raise error
File "/Users/user/Desktop/ProgrammingAndCoding/TomAndJerry/.venv/lib/python3.9/site-packages/discord/ext/commands/bot.py", line 939, in invoke
await ctx.command.invoke(ctx)
File "/Users/user/Desktop/ProgrammingAndCoding/TomAndJerry/.venv/lib/python3.9/site-packages/discord/ext/commands/core.py", line 863, in invoke
await injected(*ctx.args, **ctx.kwargs)
File "/Users/user/Desktop/ProgrammingAndCoding/TomAndJerry/.venv/lib/python3.9/site-packages/discord/ext/commands/core.py", line 94, in wrapped
raise CommandInvokeError(exc) from exc
discord.ext.commands.errors.CommandInvokeError: Command raised an exception: Forbidden: 403 Forbidden (error code: 50013): Missing Permissions
这是我的密码:-
@client.command(description="Mutes the specified user.")
@commands.bot_has_permissions(manage_roles=True)
@commands.cooldown(2,5, commands.BucketType.user)
@commands.has_permissions(manage_roles=True)
async def mute(ctx, member: discord.Member, *, reason=None):
guild = ctx.guild
mutedRole = discord.utils.get(guild.roles, name="Muted")
if not mutedRole:
mutedRole = await guild.create_role(name="Muted")
for channel in guild.channels:
await channel.set_permissions(mutedRole, speak=False, send_messages=False, read_message_history=True, read_messages=False)
embed = discord.Embed(title="Muted", description=f"{member.mention} was muted ", color=ctx.author.color)
embed.add_field(name="Reason:", value=reason, inline=False)
await ctx.send(embed=embed)
await member.add_roles(mutedRole, reason=reason)
await member.send(f" You have been muted in: {guild.name} Reason: {reason}")
编辑:-我添加了
elif isinstance(error, commands.CommandInvokeError):
await ctx.send("That user is Mod/Admin. I can't do that! If that is not the case, please place my role above the role the person has to be muted!")
所以现在,mute命令的嵌入也与“该用户是Mod/Admin”一起发送
目前没有回答
相关问题 更多 >
编程相关推荐