Hi Jain!
Is it related in any way with OutSystems?
What component are you using?
If not maybe the best place to put this question is in some other forum like Stack Overflow for example.
Any way, some ideas that can help you.
Your python code seems ok and will work, however depending on your business rule since you are using an while you should check if the Author is a Bot and if yes, return from the function.
Check this topic from stack overflow.
It is very similar with the problem you are having:

I believe if you use:
if message.author.bot:
return
You can solve your problem.
Cheers and Regards,
RR :)