Click here to Skip to main content
15,883,814 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi there. i have some problems with a discord.py file.

here is the code
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)


and i got the error

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


What I have tried:

what can i do to make this work ?
Posted
Updated 31-Jan-23 10:35am

1 solution

You need to ask in their discord server. The link to their discord server is at the top of their documentation website: Welcome to discord.py[^]
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900