我的欢迎on_member_join代码由于某种原因不起作用,我似乎无法正确处理(3天的编码经验)



这是我的代码,用于让我的机器人在get_channel中的id在特定通道中说出消息,以使用嵌入发布消息。

@client.event
async def on_member_join(member):
if member.guild.name == 'Ruthyon°•○♧':
embed=discord.Embed(title="Welcome to {member.guild.name}", url="https://discord.gg/ZzEzeEDD9K", description="", color=discord.Color.blue())
embed.set_author(name=member.author.display_name, icon_url=member.author.avatar_url)
embed.set_thumbnail(url="#enter your own url")
embed.add_field(name="Intro", value="Thank you for joining us, we hope you'll enjoy your time here in our community!", inline=False)
embed.add_field(name="Get started.", value="Head over to #╽»♡┆rules   get verified and checkout the custom roles channel.", inline=True)
embed.add_field(name="Joined", value=member.joined_at)
embed.set_image(url="#enter your own url")
embed.set_footer(text="Information requested by: {}".format(member.author.display_name))
embed.timestamp = datetime.datetime.utcnow()
await client.get_channel(869616505795514425).send(f"{member.mention}")
await client.get_channel(869616505795514425).send(embed=embed)

问题是:

Ignoring exception in on_member_join
Traceback (most recent call last):
File "/opt/virtualenvs/python3/lib/python3.8/site-packages/discord/client.py", line 343, in _run_event
await coro(*args, **kwargs)
File "main.py", line 27, in on_member_join
embed.set_author(name=member.author.display_name, icon_url=member.author.avatar_url)
AttributeError: 'Member' object has no attribute 'author'

这是因为在执行member.author时,成员表示discord.Member,而它没有任何author属性。你只需要做member.avatar_url就可以得到他们的头像。member.display_name也是如此。

最新更新