嗨,我尝试在 discord.py 中制作 Logger Bot 我的代码:
@client.event
async def on_guild_role_create(guild, role):
logs = await guild.audit_logs(limit=1, action=discord.AuditLogChanges.role_create).flatten()
channel = guild.get_channel(channel_ID)
logs = logs[0]
if logs.target == role:
#await channel.send(f'{logs.user} Created Role.')
我遇到的错误:
Ignoring exception in on_guild_role_create
Traceback (most recent call last):
File "C:\Users\MY PC\AppData\Roaming\Python\Python38\site-packages\discord\client.py", line 343, in _run_event
await coro(*args, **kwargs)
File "C:\Users\MY PC\source\repos\Event\Event\Event.py", line 32, in on_guild_role_create
logs = await guild.audit_logs(limit=1, action=discord.AuditLogChanges.role_create).flatten()
AttributeError: 'Role' object has no attribute 'audit_logs'
我该怎么办?
答案 0 :(得分:0)
on_guild_role_create
只接受一个参数,即角色。我们必须从角色中获取公会实例。
async def on_guild_role_create(role):
guild = role.guild
#other stuff here