我刚刚制作了一个应用代码的系统,但由于某种原因,剥夺用户的角色不起作用。如果我把要发送的消息放在前面,它就会发送,但错误仍然存在。
async def check_json():
while True:
with open("premium.json", "r") as f:
data = json.load(f)
if data["claimers"] != {}:
for user in data["claimers"]:
if time.time() > data["claimers"][user]:
del data["claimers"][user]
member = await bot.get_or_fetch_user(user)
guild = bot.get_guild(1155525773424345151)
role = guild.get_role(1186708852767461416)
await member.remove_roles(role)
await member.send(f"Hey! Your premium just expired. Thanks for using it :P")
with open("premium.json", "w") as f:
json.dump(data, f, indent=4)
f.close()
await asyncio.sleep(3)
抱歉,如果这个问题很愚蠢。我只是不明白错误是什么。感谢您的时间!
根据@Alpensin 的要求:
Ignoring exception in on_ready
Traceback (most recent call last):
File "C:\Users\Alexander\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.11_qbz5n2kfra8p0\LocalCache\local-packages\Python311\site-packages\disnake\client.py", line 703, in _run_event
await coro(*args, **kwargs)
File "c:\Users\Alexander\Documents\code claimer.py", line 33, in on_ready
await check_json()
File "c:\Users\Alexander\Documents\code claimer.py", line 21, in check_json
await member.remove_roles(role)
^^^^^^^^^^^^^^^^^^^
AttributeError: 'User' object has no attribute 'remove_roles