gpt4 book ai didi

python - Discord.py 命令上的“Int”对象没有属性 'id' 错误

转载 作者:行者123 更新时间:2023-12-01 08:14:02 24 4
gpt4 key购买 nike

我正在制作一个简单的审核机器人,其中一个命令用于使用 Discord.py 来操作某人(将其角色提升为审核者)。

这是有问题的命令,位于齿轮内部(命令是discord.ext.commands):

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'

最佳答案

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

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

关于python - Discord.py 命令上的“Int”对象没有属性 'id' 错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/55072155/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com