async def mute(ctx, user: discord.User,time,*,reason):
if user:
await ctx.message.delete()
if discord.utils.get(ctx.guild.roles, name="mute"):
role = discord.utils.get(ctx.guild.roles, name="mute")
addroles = []
for i in user.roles:
try:
await user.remove_roles(i)
addroles.append(i.id)
except:
print(f"Can't remove the role {i}")
await user.add_roles(role)
cmd_used("mute",ctx.author,ctx.message.content)
embed=discord.Embed(title=f"""{bot.user.name}""",colour=maincolor)
embed.add_field(name=f"""`{ctx.author}` muted you from `{user.guild.name}`""",value=f"""time: {time}s, reason: {reason}""",inline=True)
await user.send(embed=embed)
await asyncio.sleep(int(time))
await user.remove_roles(role)
print(addroles)
await user.add_roles(addroles)
#errors: AttributeError: 'list' object has no attribute 'id'
基本上,我的mute命令实际上不起作用,因为它使它们静音,并且不返回它们以前的角色。 我需要一些帮助
addroles
在本例中是用户在执行命令之前拥有的角色ID的列表。但是^{您可以将实际的角色对象保存在
addroles
中,迭代该列表并分配它们或者更好的方法是使用^{} ,因为它只向Discord API发送一个请求
例如,您可以使用命令删除用户的所有角色
正如您所看到的,这是更有效的,应该是首选的解决方案
相关问题 更多 >
编程相关推荐