“Int”对象在上没有属性“id”错误不和.py命令

2024-10-02 10:24:12 发布

您现在位置:Python中文网/ 问答频道 /正文

我正在做一个简单的调节机器人,其中一个命令是用来操作某人(提升他们的角色为调节者)使用不和.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'


Tags: theto命令ansendmodexceptionerror
2条回答

你基本上需要一些东西来给你一个discord.Memberdiscord.Role的实例,所以你必须对member实例做{},因为你已经在参数转换器中有了它,ctx.guild.get_role(392763334052544522)所以它就是await member.add_roles(ctx.guild.get_role(392763334052544522), atomic=True)。在

您需要获取代表角色的role对象,并传递该对象而不是id

role = ctx.guild.get_role(392763334052544522)
await member.add_roles(role, atomic=True)

相关问题 更多 >

    热门问题