我正在做一个简单的调节机器人,其中一个命令是用来操作某人(提升他们的角色为调节者)使用不和.py.
这是正在讨论的命令,它位于cog中(命令是不和谐外部命令)公司名称:
commands.command(name='mod', hidden = True)
#just the mods, the bot role and the server creator can use this command, hence why the decorator below:
@commands.has_any_role("role1","role2", "role3")
async def mod(self, ctx, member:discord.Member = None):
try:
if member == None:
await ctx.send('no argument given')
elif member == ctx.message.author:
await ctx.send('You already are moderator')
else:
await discord.Member.add_roles(392763334052544522, atomic=True)
except Exception as e:
await ctx.send(f"There was an error while trying to elevate {member}. Exception: {e}")
print("\n" + f"There was an error while {ctx.message.author} tried to elevate {member}. Exception: {e}")
机器人本身装载得很好。想跑的时候!mod@username#1234由于我在命令中设置的捕捉异常,这将显示在终端上
There was an error while (Mydiscorduser) tried to elevate (anotherdiscorduser). Exception: 'int' object has no attribute 'id'
你基本上需要一些东西来给你一个},因为你已经在参数转换器中有了它,
discord.Member
和discord.Role
的实例,所以你必须对member
实例做{ctx.guild.get_role(392763334052544522)
所以它就是await member.add_roles(ctx.guild.get_role(392763334052544522), atomic=True)
。在您需要获取代表角色的
role
对象,并传递该对象而不是id相关问题 更多 >
编程相关推荐