【发布时间】:2021-10-03 21:52:27
【问题描述】:
所以我做了一个命令,可以设置一个成员加入,给角色命令,它将它存储到一个 json 文件中。但是当有人加入时会出现错误:return self._roles.get(role_id) TypeError: unhashable type: 'list'。这是我的代码:
with open('join_roles.json', 'r') as f:
join_roles = json.load(f)
@client.event
async def on_member_join(member):
guild = member.guild
print(join_roles.get(str(guild.id)))
role = member.guild.get_role(join_roles.get(str(guild.id)))
await member.add_roles(role)
@client.command()
@commands.has_permissions(administrator=True)
async def joinrole(ctx, role):
join_roles[str(ctx.guild.id)] = role.split()
with open('join_roles.json', 'w') as f:
json.dump(join_roles, f)
await ctx.send(embed=discord.Embed(title=f':white_check_mark:| Member join role set to {role}!', color=0x2596be))
【问题讨论】:
-
你能显示
join_roles.json吗? -
是的,当然:{"865806960997826571": [""]}
标签: python python-3.x discord discord.py