dolfies / discord.py-self

A fork of the popular discord.py for user accounts.
https://discordpy-self.rtfd.io/en/latest/
MIT License
688 stars 160 forks source link

on_member_join get called randomly #612

Closed pingu6 closed 7 months ago

pingu6 commented 10 months ago

Summary

on_member_join get called randomly?

Reproduction Steps

i have no idea but my friend tested the same code in the same server and he reproduced the same issue

Code

import selfcord
import logging
import os
os.environ['PYTHONASYNCIODEBUG'] = '1'
import asyncio
import time
import datetime
import toml

handler = logging.FileHandler(filename="selfcord.log", encoding="utf-8", mode="w")

config = toml.load("config.toml")

token = config['token']
channel_id = config['channel_id']
server_id = config['server_id']

class MyClient(selfcord.Client):
    async def on_ready(self):
        print('Logged on as', self.user)

    async def on_member_join(self, member):
            if member.guild.id == server_id: 
                current_time = time.strftime(r"%d.%m.%Y %H:%M:%S", time.localtime()) 
                channel = self.get_channel(channel_id)

                await channel.send(f'$givekakera {member.mention} 1')
                await asyncio.sleep(1)
                await channel.send('yes')

                print(f'{member} recived the kakera reward.')
                print(f'{member.guild.id}')
                print(f'{member} joinned at ' + current_time)

client = MyClient()
client.run(token, log_handler=handler, log_level=logging.DEBUG)

Expected Results

on_member_join get called/fire when a new member join?

Actual Results

Executing <Task pending name='Task-1' coro=<Client.run.<locals>.runner() running at C:\Users\pingu\Documents\Projects\on_member_join\.venv\Lib\site-packages\selfcord\client.py:1048> wait_for=<Future pending cb=[shield.<locals>._outer_done_callback() at C:\Users\pingu\AppData\Local\Programs\Python\Python311\Lib\asyncio\tasks.py:908, Task.task_wakeup()] created at C:\Users\pingu\AppData\Local\Programs\Python\Python311\Lib\asyncio\base_events.py:427> cb=[_run_until_complete_cb() at C:\Users\pingu\AppData\Local\Programs\Python\Python311\Lib\asyncio\base_events.py:180] created at C:\Users\pingu\AppData\Local\Programs\Python\Python311\Lib\asyncio\runners.py:100> took 0.125 seconds
Executing <Task pending name='Task-1' coro=<Client.run.<locals>.runner() running at C:\Users\pingu\Documents\Projects\on_member_join\.venv\Lib\site-packages\selfcord\client.py:1048> wait_for=<Future pending cb=[Task.task_wakeup()] created at C:\Users\pingu\AppData\Local\Programs\Python\Python311\Lib\asyncio\base_events.py:427> cb=[_run_until_complete_cb() at C:\Users\pingu\AppData\Local\Programs\Python\Python311\Lib\asyncio\base_events.py:180] created at C:\Users\pingu\AppData\Local\Programs\Python\Python311\Lib\asyncio\runners.py:100> took 0.110 seconds
Logged on as xxx
<new member> recived the kakera reward.
<server id>
<new member> joinned at 23.11.2023 18:03:00
Executing <Task finished name='selfcord.py: on_member_join' coro=<Client._run_event() done, defined at C:\Users\pingu\Documents\Projects\on_member_join\.venv\Lib\site-packages\selfcord\client.py:592> result=None created at C:\Users\pingu\Documents\Projects\on_member_join\.venv\Lib\site-packages\selfcord\client.py:618> took 0.266 seconds
<old member 1> recived the kakera reward.
<server id>
<old member 1> joinned at 23.11.2023 18:03:00
<old member 2> recived the kakera reward.
<server id>
<old member 2> joinned at 23.11.2023 18:07:57
<old member 3> recived the kakera reward.
<server id>
<old member 3> joinned at 23.11.2023 18:08:13

System Information

❯ python -m selfcord -v
- Python v3.11.6-final
- selfcord.py v2.1.0-alpha
    - selfcord.py metadata: v2.1.0a4383+gc333695b
- aiohttp v3.9.0
- system info: Windows 10 10.0.19045

Checklist

Additional Information

No response

dolfies commented 8 months ago

Was able to reproduce the broken events, sorry for the delay.

dolfies commented 7 months ago

Member events are now properly dispatched by Discord, no more hacky member list parsing, so this should work perfectly now :)