reactxsw / Smilewinbot

A discord bot made with python for my discord server
https://smilewinbot.web.app/
GNU General Public License v3.0
14 stars 5 forks source link

Incorrect use of a context manager #38

Closed ghost closed 2 years ago

ghost commented 2 years ago

I was in the proxy.py file in cogs and I saw this snippet of code:

if server_language == "Thai":
                url = "https://raw.githubusercontent.com/ShiftyTR/Proxy-List/master/http.txt"
                async with aiohttp.ClientSession() as session:
                    async with session.get(url) as r:
                        r = await r.text()
                with open("data/http.txt", "w") as file:
                    file.write(r)
                file.close()
                f = nextcord.File("data/http.txt", filename="http.txt")
                await ctx.send(file=f)

When using context managers files are automatically closed! I will create a few pull requests to patch this in any file I see.

ksIsCute commented 2 years ago

oh yikes, nice spot.

ghost commented 2 years ago

thanks! reactsx merged the fix so lemme just close this issue!