dolfies / discord.py-self

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

`on_message` event triggered multiple time #485

Closed JamesTesting888 closed 1 year ago

JamesTesting888 commented 1 year ago

Summary

on_message event triggered multiple time

Reproduction Steps

  1. Bot definition:

    bot = commands.Bot(
    self_bot=False,
    command_prefix='r! ',
    captcha_handler=HCaptchaHandler()
    )
  2. on_message event

    @bot.event
    async def on_message(message):
    channel = await author.create_dm()
    await channel.send("some message")
  3. Captcha is triggered and then solved. The message was sent successfully.

Code

No response

Expected Results

The message gets sent, when the on_message event is triggered.

Actual Results

The message does get sent, but the on_message event get triggered again for the same message object.

System Information

Latest discord.py-self master branch. Python 3.9

Checklist

Additional Information

No response

JamesTesting888 commented 1 year ago

Here is the HCaptchaHandler code in case it has something to do with it.

class HCaptchaHandler(discord.CaptchaHandler):
    async def fetch_token(self, data: dict, proxy: str, proxy_auth: aiohttp.BasicAuth) -> str:
        solver = twocaptcha.TwoCaptcha('key')

        sitekey = data['captcha_sitekey']
        url = "https://discord.com/channels/@me"

        try:
            response = await asyncio.to_thread(
                solver.hcaptcha,
                sitekey=sitekey,
                url=url,
                data=data['captcha_rqdata']
            )
        except:
            raise

        print("Captcha solved")

        return response['code']
dolfies commented 1 year ago

Are you saying the message you just sent shows up in on_message? That's intended, no filtering is done. Any message Discord dispatches will be parsed and dispatched to on_message, this includes your own messages.

JamesTesting888 commented 1 year ago

No, I do filter my own message. I think it might be an internet issue as this issue is not happening consistently. Thanks for the response!