【解決方法】discord.py の対処方法

[ad_1]

やあ。 discord.py ファイルに問題があります。

ここにコードがあります

Python
<pre>@client.event
async def on_member_join(member):
    log_channel = client.get_channel(x)
    members = len(member.guild.members)
    join_time = member.joined_at
    invite = None
    # check if the member was invited
    for invite in member.guild.invites():
        if invite.uses > 0 and invite.inviter == member:
            invite = invite
            break
    embed = discord.Embed(
        title="New Member",
        description=f"{member.mention} has joined the server. With him/her, we are {members} members.",
        color=discord.Color.blue()
    )
    embed.set_thumbnail(url=member.avatar_url)
    embed.add_field(name="Created Account At", value=member.created_at.strftime("%b %d, %Y %H:%M:%S"))
    embed.add_field(name="Invited By", value=invite.inviter)
    embed.add_field(name="Invite Code", value=invite.code)
    embed.set_footer(text="x", icon_url="x")
    channel = client.get_channel(x)
    await log_channel.send(embed=embed)

@client.event
async def on_member_leave(member):
    log_channel = client.get_channel(x)
    members = len(member.guild.members)
    join_time = member.joined_at
    leave_time = datetime.datetime.now()
    time_spent = leave_time - join_time
    embed = discord.Embed(
        title="Member Left",
        description=f"{member.mention} has left the server. Without him/her, we are {members} members.",
        color=discord.Color.red()
    )
    embed.set_thumbnail(url=member.avatar_url)
    embed.add_field(name="Time Spent In Server", value=str(time_spent))
    embed.set_footer(text="x", icon_url="x")
    channel = client.get_channel(x)
    await log_channel.send(embed=embed)

そして私はエラーを得ました

File "..." 2: RuntimeWarning: coroutine 'Guild.invites' was never awaited
  for invite in member.guild.invites():
RuntimeWarning: Enable tracemalloc to get the object allocation traceback
[2023-01-31 22:21:12] [ERROR   ] discord.client: Ignoring exception in on_member_join
Traceback (most recent call last):
  File "....", line 409, in _run_event
    await coro(*args, **kwargs)
  File "....", line 192, in on_member_join
    for invite in member.guild.invites():
TypeError: 'coroutine' object is not iterable

私が試したこと:

これを機能させるにはどうすればよいですか?

解決策 1

彼らの不和サーバーで尋ねる必要があります。 不和サーバーへのリンクは、ドキュメント Web サイトの上部にあります。 discord.py へようこそ[^]

[ad_2]

コメント

タイトルとURLをコピーしました